考虑这个zip file后面的.dta
文件。你知道吗
这是第一排:
>>> df = pd.read_stata('cepr_org_2014.dta', convert_categoricals = False)
>>> df.iloc[0]
year 2014
month 1
minsamp 8
hhid 000936071123039
hhid2 91001
# [...]
>>> df.iloc[0]['wage4']
nan
我用stata
再次检查这个,它看起来是正确的。到目前为止,还不错。现在我设置了一些要保留的列并重做练习。你知道吗
>>> columns = ['wbho', 'age', 'female', 'wage4', 'ind_nber']
columns2 = ['year', 'month', 'minsamp', 'hhid', 'hhid2', 'fnlwgt']
>>> df = pd.read_stata('cepr_org_2014.dta',
convert_categoricals = False,
columns=columns+columns2)
>>> df.iloc[0]
wbho 1
age 65
female 0
wage4 1.7014118346e+38
ind_nber 101
year 2014
month 1
minsamp 8
hhid NaN
hhid2 NaN
fnlwgt 560.1073
Name: 0, dtype: object
添加要保留的列列表后,pandas
wage4
比NaN
大。你知道吗hhid
和hhid2
创建缺少的值。你知道吗为什么?你知道吗
注意:首先加载数据集,然后使用df[columns+columns2]
进行过滤。
我把这个错误追溯到熊猫的一个虫子身上。我已经修复了https://github.com/jbuyl/pandas/tree/fix-column-dtype-mixing中的错误,并打开了一个pull请求以在修复中合并,但是可以随意签出我的fork/branch。你知道吗
下面是运行您的示例的结果:
它似乎是一个bug,在
pandas/io/stat.py
的源代码中,在_do_select_columns()
方法中,循环:打乱了
dtypes
的顺序,它不再与column_set
中出现的序列匹配。你知道吗比较本例中
df2
和df3
的dtypes
:更改为:
修复了问题。你知道吗
(不知道
matched
在这里做什么。以后似乎再也不用了。)相关问题 更多 >
编程相关推荐