'Drop rows by index with date index

I need to delete the rows of a dataframe in a certain period of time, in this case my index is time, but i can't

My dataframe

i try:

df.drop(df.loc['2021-01-27 00:34:00':'2021-03-12 20:43:00'])

but the code interprets that the second term is a column



Solution 1:[1]

You can use query here:

df.query("Fecha < '2021-01-27 00:34:00' | Fecha > '2021-03-12 20:43:00'")

Solution 2:[2]

df.drop(df.loc["2017-01-02":"2017-01-05"].index)

Works.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rachwa
Solution 2 Pablo Iturra Montoya