Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas deleting row with df.drop doesn't work

I have a DataFrame like this (first column is index (786...) and second day (25...) and Rainfall amount is empty):

Day Rainfall amount (millimetres)   786   25                               787   26                               788   27                               789   28                               790   29                               791    1                               792    2                               793    3                               794    4                               795    5  

and I want to delete the row 790. I tried so many things with df.drop but nothin happend.

I hope you can help me.

like image 773
Madddin Avatar asked Jul 20 '16 12:07

Madddin


People also ask

How do I delete a row in pandas DataFrame?

To delete a row from a DataFrame, use the drop() method and set the index label as the parameter.

How do I permanently delete a row in pandas?

Pandas provides data analysts with a way to delete and filter dataframe using . drop() method. Columns can be removed permanently using column name using this method df. drop(['your_column_name'], axis=1, inplace=True) .


1 Answers

While dropping new DataFrame returns. If you want to apply changes to the current DataFrame you have to specify inplace parameter.

Option 1
Assigning back to df -

df = df.drop(790) 

Option 2
Inplace argument -

df.drop(790, inplace=True) 
like image 198
frist Avatar answered Sep 20 '22 04:09

frist