我正在尝试清理一些数据,方法是将我的浮点数设置为不显示小数点,而我的日期/时间仅显示日期。在此之后,我想用一个空字符串填充我的NaNs,但是当我这样做时,我的日期又回到了显示日期/时间的状态。知道为什么吗?也不知道如何修复它。
这是在我使用我的数据的图片运行fillna()方法之前:
#Creating DataFrame from path variable
daily_production_df = pd.read_excel(path)
#Reformated Data series to only include date (excluded time)
daily_production_df['Date'] = daily_production_df['Date'].dt.normalize()
pd.options.display.float_format = '{:,.0f}'.format
#daily_production_df = daily_production_df.fillna('')
#Called only the 16 rows that have data, including the columns/header
daily_production_df.head(16)这是我运行fillna()方法的时候:
daily_production_df = pd.read_excel(path)
#Reformated Data series to only include date (excluded time)
daily_production_df['Date'] = daily_production_df['Date'].dt.normalize()
pd.options.display.float_format = '{:,.0f}'.format
daily_production_df = daily_production_df.fillna('')
#Called only the 16 rows that have data, including the columns/header
daily_production_df.head(16)发布于 2021-01-15 00:24:59
使用normalize()不会改变列的数据类型,pandas只是在打印时停止显示时间部分,因为它们共享相同的时间部分。
我建议正确的解决方案是将列转换为实际的datetime.date,而不是使用normalize()
df['date'] = pd.to_datetime(df['date']).dt.datehttps://stackoverflow.com/questions/65722600
复制相似问题