我这里有一个简单的脚本,它获取一个响应(原始JSON),然后用panda组织它,并从中创建一个CSV。然而,我注意到其中一列是大纪元时间出于某种原因。在转换到CSV之前,将NPSDate列转换为整个dataframe的正常datetime的正确方法是什么?如果我这样尝试,它会返回这些错误:
File "NPStoGainsight.py", line 42, in <module>
NPS['NPSDate'] = pandas.to_datetime(['NPSDate'], unit='ms', utc=True)
File "/home/ec2-user/.local/lib/python2.7/site-packages/pandas/core/tools/datetimes.py", line 609, in to_datetime
result = convert_listlike(arg, box, format)
File "/home/ec2-user/.local/lib/python2.7/site-packages/pandas/core/tools/datetimes.py", line 203, in _convert_listlike_datetimes
errors=errors)
File "pandas/_libs/tslib.pyx", line 398, in pandas._libs.tslib.array_with_unit_to_datetime
NPS = pandas.DataFrame(reportData)
renamedColumns = {
'account_salesforce_total_arr__c' : 'totalARR',
'account_salesforce_pricing_package__c' : 'pricingPackage',
'account_salesforce_customer_classification__c' : 'customerClassification',
'account_salesforce_account_manager_full_name__c' : 'CSM',
'account_agent_plancommit' : 'planCommit',
'poll_543uce0tt59_eqOSduL4o25wbYsmfGbmj_pgBXY_pollResponse' : 'NPSComment',
'account_auto_id' : 'accountId',
'visitor_agent_email' : 'email',
'poll_tudk5p2oot9_eqOSduL4o25wbYsmfGbmj_pgBXY_pollResponse' : 'NPSResponse',
'poll_tudk5p2oot9_eqOSduL4o25wbYsmfGbmj_pgBXY_pollTime' : 'NPSDate'
}
NPS = NPS.rename(columns = renamedColumns)
NPS = pandas.to_datetime(NPS['NPSDate'], unit='ms')
NPS.to_csv("NPStoGainsight.csv", encoding='utf-8', index=False)
使用大纪元时间的MS日期格式(例如:1.5667E+12) 问题来源StackOverflow 地址:/questions/59381038/pandas-convert-epoch-time-before-creating-csv
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。