In mine, dataframeI change my index to a date field as
df.index = df.TRX_DATE
Now I want to cut mine dataframebased on two dates or any date difference.
But I get errors.
startdate = currentdate - timedelta(days=30)
dflast30 = df.loc[startdate:currentdate]
Tried to do, creating a mask
mask = (df['TRX_DATE'] >= startdate) & (df['TRX_DATE'] <= currentdate )
dflast30 = df.loc[mask]
dflast30 = df.loc[mask]
TypeError: unorderable types: str ()> datetime.datetime ()
Then I tried to truncate as:
dflast30 = df.truncate(before = currentdate, after = startdate)
And I get the same error.
I am embarrassed. And I need to give advice on these issues:
Is it possible to change the index (field TRX_DATE) to type datetime?
Or should I do this type of row field.
Or should I indicate the unassigned index as it is, and search the date field for my current requirement.
Or give an example of how I can make a date field as an index and slice for a date range, and please also indicate the output.