pandas 输出时间戳记to_excel(以微秒为单位) [英] pandas output timestamps to_excel with microseconds
问题描述
我在df中具有微秒的分辨率,这非常重要,但是无论我如何尝试,我都无法使用.xls或.xlsx来显示excel的微秒分辨率.关于如何在不显式转换为字符串的情况下显示它们的任何想法?
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?
推荐答案
使用GitHub上的最新版本的Pandas(以及即将发布的0.13.1),您可以在ExcelWriter()
中指定Excel日期格式,例如这个:
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()
将显示微秒(或至少毫秒,因为这是Excel的显示限制):
Which will display the microsecond times (or at least milliseconds since that is Excel's display limit):
另请参见使用Python熊猫和XlsxWriter .
这篇关于 pandas 输出时间戳记to_excel(以微秒为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!