I use pandas.to_datetime
to parse the dates in my data. Pandas by default represents the dates with datetime64[ns]
even though the dates are all daily only.
I wonder whether there is an elegant/clever way to convert the dates to datetime.date
or datetime64[D]
so that, when I write the data to CSV, the dates are not appended with 00:00:00
. I know I can convert the type manually element-by-element:
[dt.to_datetime().date() for dt in df.dates]
But this is really slow since I have many rows and it sort of defeats the purpose of using pandas.to_datetime
. Is there a way to convert the dtype
of the entire column at once? Or alternatively, does pandas.to_datetime
support a precision specification so that I can get rid of the time part while working with daily data?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…