这是我的Pandas数据帧:
db.head()
db.to_csv('ANOVA_TEST.csv')
grade class numgrade numyear
0 A Senior 12 4
1 A Junior 12 3
2 A Junior 12 3
3 A Senior 12 4
4 A Junior 12 3
我创建了两个新的数据框,如下所示:
num_columns = ['numgrade', 'numyear']
dnum = db [num_columns].copy()
str_columns = ['numgrade', 'class']
dstr = db [str_columns].copy()
dnum.to_csv('ANOVA_TEST_num.csv')
dstr.to_csv('ANOVA_TEST_str.csv')
dnum.head(2)
dstr.head(2)
numgrade numyear
0 12 4
1 12 3
numgrade class
0 12 Senior
1 12 Junior
为确保一切顺利,以下是每列的值类型:
print 'dnum["numgrade"]',type(dnum["numgrade"][1])
print 'dnum["numyear"]',type(dnum["numyear"][1])
print 'dstr["numgrade"]', type(dstr["numgrade"][1])
print 'dstr["class"]',type(dstr["class"][1])
>> dnum["numgrade"] <type 'numpy.int64'>
>> dnum["numyear"] <type 'numpy.int64'>
>> dstr["numgrade"] <type 'numpy.int64'>
>> dstr["class"] <type 'str'>
现在,我尝试使用描述为here和here的 ANOVA1Way ,并在创建 pyvttbl 数据帧后再次检查类型。< / p>
from pyvttbl import DataFrame
df = DataFrame()
df.read_tbl('ANOVA_TEST_num.csv')
print type(df)
print type (df['numgrade'][1])
print type (df['numyear'][1])
>> <class 'pyvttbl.base.DataFrame'>
>> <type 'numpy.int64'>
>> <type 'numpy.int64'>
aov_pyvttbl = df.anova1way('numgrade', 'numyear')
print aov_pyvttbl
#Lengthy error message ending with:
TypeError: unsupported operand type(s) for +: 'float' and 'NoneType'
当我尝试使用&#34;字符串&#34时,也会生成相同的错误消息。 &#39; ANOVA_TEST_str.csv&#39;
中的自变量版本接下来,考虑到问题可能与转换和从 csv 文件读回有关,我尝试使用原始数据框从头开始,如上所述here:< / p>
numdep = db['numgrade'].tolist()
numindep = db['numyear'].tolist()
print len(numdep), type(numdep), type(numdep[0])
print len(numindep), type(numindep), type(numindep[0])
>> 890 <type 'list'> <type 'int'>
>> 890 <type 'list'> <type 'int'>
df3 = DataFrame()
df3['data'] = numdep
df3['conditions'] = numindep
aov = df3.anova1way('data', 'conditions')
我收到完全相同的错误消息。我也尝试将 numdep 转换为float,将 numindep 转换为str和numpy.str,但仍然遇到相同的错误。 任何人都可以弄清楚这里发生了什么?感谢您的帮助。
使用Canopy 1.7.4.3348,jupyter 1.0.0-20,pandas 0.19.0-2和pyvttbl 0.5.2.2
答案 0 :(得分:0)
我知道这是一个非常老的问题,但是确实如此。
问题在于pyvttbl依赖于旧的numpy版本(<= 1.1.x)。更多细节请参考[1]。
链接 [1] [https://www.marsja.se/four-ways-to-conduct-one-way-anovas-using-python/]