I have a dataframe like this:
tanggal_tweet datetime64[ns, UTC]
pengguna object
isi_tweet object
sentimen object
dtype: object
but when I applied with df.to_excel
it returns an error:
ValueError: Excel does not support datetime with timezone
Based on this answer https://stackoverflow.com/a/63238008/17202382, I did this
df['tanggal_tweet'] = df['tanggal_tweet'].apply(lambda a: pd.to_datetime(a).date())
and then:
df.to_excel()
When I look at the excel file, I look at tanggal_tweet
, but there is no time information, just the date. My question is, how to convert the dataframe to excel without removing the time?
CodePudding user response:
You can remove timezone information with tz_localize
:
df['tanggal_tweet'] = df['tanggal_tweet'].dt.tz_localize(None)