【问题标题】:How to export data frame in Jupyter as a csv file如何将 Jupyter 中的数据框导出为 csv 文件
【发布时间】:2021-08-04 05:40:39
【问题描述】:

我在 jupyter 笔记本中保存为 df 的数据框,我想将其导出到桌面上的 csv 文件中。

【问题讨论】:

    标签: python dataframe jupyter


    【解决方案1】:

    对于 pandas 数据框,您可以使用 df.to_csv('data.csv')

    https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_csv.html

    【讨论】:

    • data.csv 文件存储在哪里?
    • 它与您运行代码的位置有关,在这种情况下与您的笔记本在同一目录中
    【解决方案2】:

    如果您在 pandas DataFrame 中有数据,那么您可以使用 pandas 中的 .to_csv() 函数以 CSV 格式导出数据。

    在桌面上保存数据的方法如下

    df.to_csv("<path to desktop and filename>")
    
    # If you just use file name then it will save CSV file in working directory.
    # Example path : C:/Users/<>/Desktop/<file name>.csv
    

    如果您想了解更多信息,可以访问official documentation

    【讨论】:

      猜你喜欢
      • 2020-02-10
      • 1970-01-01
      • 1970-01-01
      • 2011-10-04
      • 1970-01-01
      • 1970-01-01
      • 2022-12-07
      • 1970-01-01
      • 2018-09-05
      相关资源
      最近更新 更多