How to skip rows while reading pandas dataframe?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

How to skip rows while reading pandas dataframe?

How to skip rows while reading pandas dataframe?

This recipe helps you skip rows while reading pandas dataframe

0

Recipe Objective

While working with dataframes, importing can be a tedious task if we know that some reduntant rows prexist in our dataset. To handle them, skip rows command can become quite handy.

So this recipe is a short example on how to skip rows while reading pandas dataframe. Let's get started.

Step 1 - Import the library

import pandas as pd import seaborn as sb

Let's pause and look at these imports. Pandas is generally used for performing mathematical operation and preferably over arrays. Seaborn is just for importing dataset for now.

Step 2 - Setup the Data

df = sb.load_dataset('tips') df.to_csv('tips.csv') df1=pd.read_csv('tips.csv') print(df1.head())

Here we have simply imported tips dataset from seaborn library and thereby saved it as a csv file in existing directory. Furthermore (from 3rd line), we have imported our dataset in df variable.

Step 3 - Performing skip rows operation while importing.

df2=pd.read_csv('tips.csv',skiprows=[1,2,4]) print(df2.head())

Here, we are trying to understand the importance of skiprows command. We are ignoring 1,2 and 4th rows while reading our dataset.

Step 4 Let's look at our dataset now

Once we run the above code snippet, we will see:

Scroll down to the ipython file below to see the output of the present operations.

Relevant Projects

Resume parsing with Machine learning - NLP with Python OCR and Spacy
In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Music Recommendation System Project using Python and R
Machine Learning Project - Work with KKBOX's Music Recommendation System dataset to build the best music recommendation engine.

Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

Demand prediction of driver availability using multistep time series analysis
In this supervised learning machine learning project, you will predict the availability of a driver in a specific area by using multi step time series analysis.

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Perform Time series modelling using Facebook Prophet
In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.