This seems like a straightforward question, but I've been stuck for a while on it now. Apologies if this has been asked already. I have the following pandas dataframe:
import pandas as pd
zed = pd.DataFrame({'gameDate': {0: datetime.date(2019, 12, 12),
1: datetime.date(2019, 12, 12),
2: datetime.date(2019, 12, 12),
3: datetime.date(2019, 12, 12),
4: datetime.date(2019, 12, 12)},
'periodType': {0: 'REGULAR',
1: 'REGULAR',
2: 'REGULAR',
3: 'REGULAR',
4: 'REGULAR'}})
and when I check to see the dtypes of this dataframe, I get the following output:
print(zed.dtypes)
gameDate object
periodType object
dtype: object
How can the date types be distinguished from the string types when both are returned as object? I have a much larger dataframe for which I need to identify all columns of type date (not datetime or timestamp, but specifically date only, like above), but I don't specifically know the column names. I'd like to use something like the .dtypes function to help reveal these columns.
I could create a function that tests if the string is of the format yyyy-mm-dd, but that seems tedious.
Thanks!
datetime.date?pandasis compatible with thenp.datetime64[ns]andnp.timedelta64[ns]dtypes. Because the datetime module is not the supported library there are several issues that you can encounter: stackoverflow.com/questions/60888277/… and stackoverflow.com/questions/60256108/… are two examples where pandas diverges from the standard datetime module.datetype in the database, and it seems looks like python / pandas is simply auto-casting the column intodatetime.date.np.datetime64[ns]", but this can be looked up easilyzed.iloc[0].apply(type)?