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

Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

Predict Credit Default | Give Me Some Credit Kaggle
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

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.

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

Data Science Project-TalkingData AdTracking Fraud Detection
Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

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.

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

Forecast Inventory demand using historical sales data in R
In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.