pandas to csv TypeError: get_handle() 得到了一个意外的关键字参数“错误" [英] pandas to csv TypeError: get_handle() got an unexpected keyword argument 'errors'

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

问题描述

我有一张大桌子,我根据它们的日期将其切成许多小桌子:

<预><代码>dfs={}对于 fechas 中的 fecha:dfs[fecha]=df[df['date']==fecha].set_index('小时')#现在我可以像这样访问表格:dfs['2019-06-23'].head()

我对 dfs['2019-06-23'] 特定表做了一些修改,现在我想将它保存在我的电脑上.我尝试通过两种方式做到这一点:

#first try:dfs['2019-06-23'].to_csv('specific/path/file.csv')#第二次尝试:test=dfs['2019-06-23']test.to_csv('test.csv')

他们都提出了这个错误:

<块引用>

TypeError: get_handle() 得到了一个意外的关键字参数 'errors'

我不知道为什么会出现这个错误,也没有找到任何原因.我已经用这种方式保存了很多文件,但以前从未有过.

我的目标:能够在我修改后将此数据框保存为 csv

解决方案

最后是使用 pd.DataFrame 然后将其导出如下:

to_export=pd.DataFrame(dfs['2019-06-23'])to_export.to_csv('my_table.csv')

这让我很惊讶,因为当我检查表的类型时收到错误时,它是 dataframe .然而,它是这样工作的.

I had big table which I sliced to many smaller tables based on their dates:


dfs={}
for fecha in fechas:
    dfs[fecha]=df[df['date']==fecha].set_index('Hour')
#now I can acess the tables like this:
dfs['2019-06-23'].head()

I have done some modifictions to the dfs['2019-06-23'] specific table and now I would like to save it on my computer. I have tried to do this in two ways:

#first try:
dfs['2019-06-23'].to_csv('specific/path/file.csv')

#second try:
test=dfs['2019-06-23']
test.to_csv('test.csv')

both of them raised this error:

TypeError: get_handle() got an unexpected keyword argument 'errors'

I don't know why I get this error and haven't find any reason for that. I have saved many files this way but never had that before.

My goal: to be able to save this dataframe after my modification as csv

解决方案

In the end what worked was to use pd.DataFrame and then to export it as following:

to_export=pd.DataFrame(dfs['2019-06-23'])

to_export.to_csv('my_table.csv')

that suprised me because when I checked the type of the table when I got the error it was dataframe . However, this way it works.

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

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