When I try to run this in Jupyter Notebook:
isolated = diff['2012-09-28' <= diff['start_date']]
isolated
I get this:
TypeError: '>=' not supported between instances of 'datetime.date' and 'str'
What should I do? I already tried importing pandas and datetime but it didn't work.
CodePudding user response:
Check your time and date. Then run the program agian to see if it works.
CodePudding user response:
Convert column to datetimes:
diff['2012-09-28' <= pd.to_datetime(diff['start_date'])]
Or convert string to date:
diff[pd.Timestamp('2012-09-28').date() <= diff['start_date']]
CodePudding user response:
Strings cannot be compared directly; they need to convert to suitable data format for comparison.
**Use this sort of formatting. **
import pandas as pd
df = pd.read_csv("dataframe.csv")
startdate = pd.to_datetime("date").date()
enddate = pd.to_datetime("date").date()