
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
Python Pandas - How to delete a row from a DataFrame
To delete a row from a DataFrame, use the drop() method and set the index label as the parameter.
At first, let us create a DataFrame. We have index label as w, x, y, and z:
dataFrame = pd.DataFrame([[10, 15], [20, 25], [30, 35], [40, 45]],index=['w', 'x', 'y', 'z'], columns=['a', 'b'])
Now, let us use the index label and delete a row. Here, we will delete a row with index label ‘w’
dataFrame = dataFrame.drop('w')
Example
Following is the code
import pandas as pd # Create DataFrame dataFrame = pd.DataFrame([[10, 15], [20, 25], [30, 35], [40, 45]],index=['w', 'x', 'y', 'z'],columns=['a', 'b']) # DataFrame print"DataFrame...\n",dataFrame # deleting a row dataFrame = dataFrame.drop('w') print"DataFrame after deleting a row...\n",dataFrame
Output
This will produce the following output
DataFrame... a b w 10 15 x 20 25 y 30 35 z 40 45 DataFrame after deleting a row... a b x 20 25 y 30 35 z 40 45
- Related Articles
- How to delete a column from Pandas DataFrame
- How to delete a column from a Pandas DataFrame?
- Python Pandas - How to select rows from a DataFrame by passing row label
- How to append a list as a row to a Pandas DataFrame in Python?
- Python - How to select a column from a Pandas DataFrame
- How to get nth row in a Pandas DataFrame?
- Create a Pipeline and remove a row from an already created DataFrame - Python Pandas
- Apply function to every row in a Pandas DataFrame in Python
- Python Pandas - How to select multiple rows from a DataFrame
- Python Pandas – How to skip initial space from a DataFrame
- How to get the row count of a Pandas DataFrame?
- Python – Strip whitespace from a Pandas DataFrame
- Python - How to drop the null rows from a Pandas DataFrame
- Apply function to every row in a Pandas DataFrame
- Deleting a DataFrame row in Python Pandas based on column value

Advertisements