How to Remove a Row From a Data Frame in Pandas (Python)

How to Remove a Row From a Data Frame in Pandas (Python)

Channel:
Subscribers:
44,100
Published on ● Video Link: https://www.youtube.com/watch?v=9yF2l0WPENM



Category:
Guide
Duration: 1:57
8,317 views
92


This video shows how to delete rows Data Frames in the Pandas library for Python.

If you find this video useful, like, share and subscribe to support the channel!
► Subscribe: https://www.youtube.com/c/DataDaft?sub_confirmation=1


Code used in this Python Code Clip:

import pandas as pd

import statsmodels.api as sm #(To access mtcars dataset)
mtcars = sm.datasets.get_rdataset("mtcars", "datasets", cache=True).data

mtcars.head()

# Delete rows by name with df.drop()

mtcars = mtcars.drop(["Mazda RX4 Wag"], # Rows to drop
axis = 0) # 0 for rows

mtcars.head()

# Delete rows by index

mtcars = mtcars.drop(mtcars.index[[0,2]], # Rows indicies to drop
axis = 0) # 0 for rows

mtcars.head()


* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones. .


⭐ Kite is a free AI-powered coding assistant that integrates with popular editors and IDEs to give you smart code completions and docs while you’re typing. It is a cool application of machine learning that can also help you code faster! Check it out here: https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=datadaft&utm_content=description-only







Tags:
remove a row from a data frame in python
remove a row from a data frame in pandas
pandas dataframes
learn pandas
pandas
python
python dataframes
delete a row from a data frame in pandas
pandas remove rows
pandas delete rows
remove row from data frame
delete row from data frame
delete from data frame
delete from dataframes
remove rows
delete rows
pandas drop rows
df.drop
df.drop()
pandas basics
pandas delete data
pandas delete records
pandas remove records