为什么在使用StyleFrame时索引列的标题不显示sf.至excel()?

2024-09-27 15:22:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一个脚本,其中我希望输出是一个自动调整列宽的Excel工作表。此外,我还希望显示索引列的标题。你知道吗

现在,我运行脚本,Excel工作表会填充自动调整的列宽,但索引列的标题不会出现。有捷径吗 解决这个问题?你知道吗

for type in tickers:
    df5 = pd.DataFrame(df4.diff(periods=1, axis=0))
    frames = [df4.iloc[-2,:],df4.iloc[-1,:],df5.iloc[-1,:]]
    df6 = pd.concat(frames, axis=1, ignore_index=True)
    df6 = round(df6, 2)
    df6.columns = ["Last Week ($mm/bp)", "This Week ($mm/bp)", "Change ($mm/bp)"]
    df6.index.name = "{}".format(type)
    df6 = df6.reindex(index = ["ED1 Comdty", "TU1 Comdty", "FV1 Comdty", "TY1 Comdty", "UXY1 Comdty", "US1 Comdty", "WN1 Comdty", "Total"])
    sf = StyleFrame(df6)
    sf.to_excel(writer, sheet_name=type, index=True)
    writer.save()

StyleFrame Output


Tags: 脚本标题indexframestypeexcelpdmm

热门问题