pandas output timestamps to_excel with microseconds

风流意气都作罢 提交于 2019-12-11 02:35:05

问题


I have microsecond resolution in my df which is very important but no matter what I try, I can't get excel to show microsecond resolution with either .xls or .xlsx. Any ideas on how to get them to display without converting to a string explicitly?


回答1:


With the latest version of Pandas on GitHub (and in the soon to be released 0.13.1) you can specify the Excel date format in the ExcelWriter() like this:

import pandas as pd
from datetime import datetime

df = pd.DataFrame([datetime(2014, 2, 1, 12, 30, 5, 60000)])

writer = pd.ExcelWriter("time.xlsx", date_format='hh:mm:ss.000')

df.to_excel(writer, "Sheet1")

writer.close()

Which will display the microsecond times (or at least milliseconds since that is Excel's display limit):

See also Working with Python Pandas and XlsxWriter.



来源:https://stackoverflow.com/questions/21650362/pandas-output-timestamps-to-excel-with-microseconds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!