I have DataFrame in Pythonlike below where data is in index (we can name this column “date”):
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).
Advertisement
Answer
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')]