27
votes

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.

1
try this: df = df[df.index != 790] - MaxU
post your code that you claim didn't work, firstly did you assign back the result of drop? ie. df = df.drop(790), are you sure the first column is the index? what does df.index show? - EdChum
if that is not the index then df[df['Day'] != 790] will work as 'Day' is a column and not the index, show the output from df.info() - EdChum
Yes it is the index. I know my Question is not so clear, but it worked with the code from MaxU. - Madddin
Your question is unclear because you didn't include your complete code, stating that a function didn't work does not give a complete picture - EdChum

1 Answers

68
votes

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)