gpt4 book ai didi

python - Pandas applymap内存错误

转载 作者:行者123 更新时间:2023-12-01 01:49:12 33 4
gpt4 key购买 nike

我正在尝试将日期时间的所有实例更改为字符串并将我的数据框导出到 Excel。数据帧可能有 20,000 - 50,000 个条目。这是我当前的代码:

wb = xw.Book('filelname.xlsx')
sht = wb.sheets['FNC']
data = wb.sheets['Data']
smdata = wb.sheets['Social']

df_sm_temp = sm_all

df_sm_temp['Date'] = df_sm_temp['Date'].apply(lambda x: str(x) if isinstance(x, datetime.time) else x)
df_sm_temp['Added'] = df_sm_temp['Added'].apply(lambda x: str(x) if isinstance(x, datetime.time) else x)
df_sm_temp['Updated'] = df_sm_temp['Updated'].apply(lambda x: str(x) if isinstance(x, datetime.time) else x)

smdata.range('SM_ALL').value = df_sm_temp

当尝试运行此程序时,我收到内存错误。任何帮助将不胜感激!

这是数据集的一个小样本:https://www.sendspace.com/file/jxhmx2

谢谢

最佳答案

实际上你不需要转换数据本身,只需将datetime_formatxlsxwriter引擎结合使用即可:

演示:

writer = pd.ExcelWriter('/path/to/result.xlsx', engine='xlsxwriter', 
date_format='mm/dd/yyyy', datetime_format='mm/dd/yyyy')

df.to_excel(writer)

关于python - Pandas applymap内存错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50905695/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com