[英]Pandas does not retain frequency format when exporting to excel
我有一個月度數據框,並且在對年度數據重新采樣后,我使用了熊貓to_period('M')以月度格式顯示索引。 很好 當我導出到excel時,它是datetime格式。 導出到excel時如何保留格式。
Jupyter Notebook中的數據樣本:
2014 1463 146.416667 1110.877414 197.230546 199.230546
Excel中的數據樣本:
2014-01-01 00:00:00 1463 146.416667 1110.877414 197.230546 199.230546
@Arthur Gouveia:感謝您的回復!
我試圖將數據類型更改為字符串並工作。 但是有更好的解決方案嗎?
if type(TNA_BB2_a.index)==pd.tseries.period.PeriodIndex:
TNA_BB2_a.index = TNA_BB2_a.index.strftime('%Y')
if type(tna_n_m_BB.index)==pd.tseries.period.PeriodIndex:
tna_n_m_BB.index = tna_n_m_BB.index.strftime('%Y-%m')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.