1

I have DataFrame in Pythonlike below where data is in index (we can name this column "date"):

enter image description here

and I would like to select all column of this DF where data in index is > than 01.01.2020, how can I do it? (be aware that date is in index).

1 Answer 1

1

Use boolean indexing:

df.index = pd.to_datetime(df.index, dayfirst=True)
df1 = df[df.index > '2020-01-01']

Or:

df.index = pd.to_datetime(df.index, dayfirst=True)
df1 = df[df.index > pd.to_datetime('2020-01-01')]
Sign up to request clarification or add additional context in comments.

1 Comment

I have error like below when I sue your code: TypeError: '>' not supported between instances of 'str' and 'Timestamp'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.