【问题标题】:Saving the header of a dataframe to a csv file in pandas将数据帧的标头保存到熊猫中的 csv 文件
【发布时间】:2023-03-17 20:14:01
【问题描述】:

我在 pandas 中有一个这样的数据框

Name    Age    Gender
Emily   10     female
Rob     12     male

我想从这个数据框中保存一个 csv 文件,让它看起来像这样

Index     ColumnName
0         Name
1         Age
2         Gender

我在网上找不到任何可以告诉我如何做到这一点的东西。

【问题讨论】:

    标签: pandas export-to-csv


    【解决方案1】:
    pd.DataFrame({"ColumnName": df.columns}).to_csv("path/to/file.csv")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-01
      • 2017-01-04
      • 1970-01-01
      • 2019-05-21
      • 2020-12-30
      • 1970-01-01
      • 2017-01-11
      • 1970-01-01
      相关资源
      最近更新 更多