user11055831
user11055831

Reputation:

how to delete a particular Row when timestamp as a index in python

i am having a error while i am trying drop a row, i think problem occurs because my date is in a index

here is my data frame -:

                cast
   date          
2022-01-01      31.0
2022-01-02      01.0
2022-01-03      02.0
2022-01-04      12.0
2022-01-05     320.0
2021-01-06      04.0

here timestamp is in my index and i am not able to drop that last row using df.drop i added some condition in it and applied on data frame .

error is labels ['2021-01-06'] not contained in axis

i use this in all the way , but it did not work out

thank you

Upvotes: 2

Views: 193

Answers (1)

DYZ
DYZ

Reputation: 57033

Your index is apparently of type DatetimeIndex. You must convert the date to drop to the same datatype:

df.drop(pd.to_datetime('2021-01-06'))

Upvotes: 3

Related Questions