I have a df
column with two columns, df.info()
yields the following:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 200 entries, 0 to 199
Data columns (total 2 columns):
date 200 non-null object
all_events 200 non-null int64
dtypes: int64(1), object(1)
memory usage: 3.2+ KB
Question:
How can convert the df['date']
into a datetime
object?
Relevant Research:
- Pandas: convert column of dataframe to datetime
- Convert Pandas Column to DateTime
- Converting object column in pandas dataframe to datetime
What I have tried:
df['date'] = pd.to_datetime(df['date'], infer_datetime_format=True)
df['date'] = pd.to_datetime(df['date'], format='%Y-%m-%d %H:%M:%S')
df['date'] = pd.to_datetime(df['date'].str.strip(), format='%Y-%m-%d %H:%M:%S')
Problem:
whatever I have I tried, I always get the following message:
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''