pandas 熊猫数据框 .to_csv

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23009415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 21:55:26  来源:igfitidea点击:

Pandas dataframe .to_csv

pandasexport-to-csv

提问by Jason

I'm trying to use pandas.DataFrame.to_csvto export a DataFrameto a .csvfile, however after running the following code there's no output:

我正在尝试pandas.DataFrame.to_csv将 a 导出DataFrame.csv文件,但是在运行以下代码后没有输出:

collist = sve2_all.columns
path_d = 'C:\Users\Desktop\From EPD'
sve2_all.to_csv('sve2_all', path = path_d, columns = collist)

Docs

文档

回答by EdChum

I think what you are doing won't work as the path is not being used to set the destination path and resulting csv

我认为您所做的将不起作用,因为该路径未用于设置目标路径和生成的 csv

This should work:

这应该有效:

import os
path_d = 'C:\Users\Desktop\From EPD'
sve2_all.to_csv(os.path.join(path_d, 'sve2_all.csv'))

Also, you are passing a string as the first parameter to to_csvwhich is probably confusing it also as it should be a fully qualified path or buffer for path_or_bufparameter.

此外,您将一个字符串作为第一个参数传递给to_csv它,这可能也会混淆它,因为它应该是path_or_buf参数的完全限定路径或缓冲区。