Removing a row from a temporary indexed frame in Python / Pandas

I am trying to delete a row in a Dataframe in Python by simply passing the date and time.

The dataframe has the following structure:

Date_Time Price1 Price2 Price3 2012-01-01 00:00:00 63.05 41.40 68.14 2012-01-01 01:00:00 68.20 42.44 59.64 2012-01-01 02:00:00 61.68 43.18 49.81 

I'm trying with df = df.drop('2012-01-01 01:00:00')

But I keep getting the following error message:

 exceptions.ValueError: labels [2012-01-01 01:00:00] not contained in axis 

Any help with deleting a row or just deleting values ​​would be greatly appreciated.

:-)

+4
source share
1 answer

It looks like you should use Timestamp instead of the line:

 In [11]: df1 Out[11]: Price1 Price2 Price3 Date_Time 2012-01-01 00:00:00 63.05 41.40 68.14 2012-01-01 01:00:00 68.20 42.44 59.64 2012-01-01 02:00:00 61.68 43.18 49.81 In [12]: df1.drop(pd.Timestamp('2012-01-01 01:00:00')) Out[12]: Price1 Price2 Price3 Date_Time 2012-01-01 00:00:00 63.05 41.40 68.14 2012-01-01 02:00:00 61.68 43.18 49.81 

Assuming DateTime is an index if not used

 df1 = df.set_index('Date_Time') 
+9
source

Source: https://habr.com/ru/post/1481419/


All Articles