pandas 和Stata 13文件 [英] pandas and Stata 13 files

查看:86
本文介绍了 pandas 和Stata 13文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了熊猫0.13.1,但是pandas.read_stata()无法读取以Stata 13格式创建的 .dta 文件,错误

I have pandas 0.13.1 installed but pandas.read_stata() fails to read .dta files created in Stata 13 format, with the error

TypeError: cannot concatenate 'str' and 'NoneType' objects

以Stata 12格式保存的相同数据集完全没有问题.

No problem at all with the same dataset saved in Stata 12 format.

我认为最新版本的熊猫(0.13.1)处理了Stata 13数据集文件.我在做错什么吗?

I thought that the latest release of pandas (0.13.1) handled Stata 13 dataset files. Am I doing something wrong?

推荐答案

我的猜测是您没有做任何天生的错误,但是您的熊猫版本无法处理Stata 13数据集文件.如 help dta 所述,Stata .dta数据集的格式随版本的发布而改变. Stata13.

My guess is you're not doing anything inherently wrong, but that your version of pandas can't handle Stata 13 dataset files. As documented in help dta, the format of Stata .dta datasets changed with the release of Stata 13.

解决方案1.

将您的熊猫更新为v0.14.0(2014年5月31日):

Update your pandas to v0.14.0 (May 31 , 2014):

read_stata现在接受Stata 13格式(GH4291)

read_stata now accepts Stata 13 format (GH4291)

来源: http://pandas.pydata.org/pandas-docs /stable/whatsnew.html

解决方案2.

如果您可以使用Stata,则有多种方法可以还原到较早版本的熊猫所使用的较早/不同格式.查看此答案:

If you have access to Stata, there are several ways of reverting to earlier/different formats that should work with your earlier version of pandas. See this answer:

在R中读取Stata 13文件

解决方案3.

GitHub 中进行了一些讨论之后,熊猫似乎与Stata 13有关数据集是 string 变量.因此,另一种解决方案是将字符串转换为数字类型.请参见help encode,它将创建适当的值标签;请参阅.如果字符串恰好是字符串类型中的数字,则可能是help realhelp destring.

After some discussion in GitHub the problem pandas seems to have with Stata 13 datasets are string variables. So another solution could be converting the string to numeric type. See help encode, which will create appropiate value labels; or maybe help real or help destring, if the strings happen to be just numbers in string type.

这篇关于 pandas 和Stata 13文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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