Jul-23-2024, 06:41 PM
(Jul-23-2024, 02:11 AM)Scott Wrote: Sorry one more quick question, can I do this or is it bad practice:Use
dt.normalize()
then you don't mess up types,which should be datetime64[ns]
.Remember the first thing to always with a dataframe is to check
dtypes
. import pandas as pd from io import StringIO data = StringIO( """OBJECTID,Start Date 1,2018-01-11 12:00:00 2,2018-11-01 12:00:00 3,2019-04-11 12:00:00 4,2021-11-03 12:00:00""") df = pd.read_csv(data, parse_dates=["Start Date"], index_col="OBJECTID") df["Start Date"] = df["Start Date"].dt.normalize() #df["Start Date"] = df["Start Date"].dt.date print(df) print(df.dtypes) print('-' * 25) print(df.info())
Output: Start Date
OBJECTID
1 2018-01-11
2 2018-11-01
3 2019-04-11
4 2021-11-03
Start Date datetime64[ns]
dtype: object
-------------------------
<class 'pandas.core.frame.DataFrame'>
Index: 4 entries, 1 to 4
Data columns (total 1 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Start Date 4 non-null datetime64[ns]
dtypes: datetime64[ns](1)
memory usage: 64.0 bytes
None