pandas :to_csv()得到了意外的关键字参数 [英] Pandas : to_csv() got an unexpected keyword argument

查看:70
本文介绍了 pandas :to_csv()得到了意外的关键字参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用数据框to_csv函数中的某些参数时,它会引发TypeError,例如`TypeError:to_csv()得到了意外的关键字参数'doublequote'

While I am trying to use some of the parameters in dataframe to_csv function, it throws an TypeError, such as `TypeError: to_csv() got an unexpected keyword argument 'doublequote'

df.to_csv('transactions.x',header = False,doublequote = False)或者 df.to_csv('transactions.x',doublequote = False)

我的熊猫版本为0.19.2(已通过 print(pd .__ version __)进行检查)我正在使用 Python 3.5

My pandas version is 0.19.2 (Checked with print(pd.__version__)) I am using Python 3.5

以下官方文档基于0.19.2.尽管我遇到类型错误,但可以说这些参数可以用作可选参数. http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_csv.html

The following official document is based on 0.19.2. Although, I am having type errors, it is stated that these parameters can be used as an optional. http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_csv.html

你们对此有什么想法吗?

Do you guys have any idea about it?

谢谢.

解决方案

感谢所有评论者的头脑风暴.

Thanks for brain storming with all commenters.

在使用以下命令 df = df.groupby(['Transactions'])['Items'].apply(','.join)之后,数据框变为系列.

After using following the command df = df.groupby(['Transactions'])['Items'].apply(','.join), dataframe becomes series.

为了将序列转换为数据框,此命令 df = df.groupby([['Transactions'])['Items'].apply(','.join).to_frame()应该改为使用.

In order to cast series to dataframe, this command df = df.groupby(['Transactions'])['Items'].apply(','.join).to_frame() should be used instead.

最后,要通过避免转义字符将其导出为具有非引号样式的CSV,您需要使用以下命令结束 df.to_csv('transactions.x',header = False,quoting = csv.QUOTE_NONE,escapechar ='')#或其他逸出字符.

Finally, to export it as a CSV with non-quote style by avoiding escape char, you need to end up with the following command df.to_csv('transactions.x', header=False, quoting=csv.QUOTE_NONE, escapechar=' ') #or whatever escapechar.

希望它对每个人都有帮助.谢谢

Hopefully, it helps for everyone. Thanks

推荐答案

此帮助:

pd.to_csv('test.csv', quoting=csv.QUOTE_NONE)

根据您的评论,阅读 docs 系列.

As per your comment, read docs on series.

您可以在保存前使用 to_frame 解决问题.

You can use to_frame before saving to resolve your issue.

这篇关于 pandas :to_csv()得到了意外的关键字参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆