I can check column types using df.dtypes, where df is pandas DataFrame. However, my question is a bit different. I have the following DataFrame:
col1 col2
0 <class 'pandas._libs.tslibs.timestamps.Timestamp'>
1 <class 'pandas._libs.tslibs.timestamps.Timestamp'>
2 <class 'float'>
3 NaN
4 <class 'pandas._libs.tslibs.timestamps.Timestamp'>
The df["col2"].dtypes returns object.
I need to create a new column is_timestamp that would check if col2 value is pandas timestamp. For testing, I tried this code:
isinstance(df_viz["col2"][0], pd._libs.tslibs.timestamps.Timestamp)
But it returns False.
The expected output:
col1 col2 col3
0 <class 'pandas._libs.tslibs.timestamps.Timestamp'> Yes
1 <class 'pandas._libs.tslibs.timestamps.Timestamp'> Yes
2 <class 'float'> No
3 NaN No
4 <class 'pandas._libs.tslibs.timestamps.Timestamp'> Yes