这是我的潘达斯数据
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我创建了两个新的dataframes,如下所示:
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'>现在,我尝试使用ANOVA1Way,如描述的这里和这里,并在创建pyvttbl数据后再次检查类型。
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'当我尝试在'ANOVA_TEST_str.csv'中使用自变量的"string“版本时,也会生成相同的错误消息。
接下来,考虑到这个问题可能与csv文件的转换和读取有关,我尝试使用原始的dataframe从头开始执行,正如所描述的这里。
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,熊猫0.19.0-2和pyvttbl 0.5.2.2
发布于 2019-01-02 09:47:23
我知道这是个很老的问题,但现在开始了。
问题是pyvttbl依赖于旧的numpy版本(<=1.1.x)。更多细节请到1点。
1https://www.marsja.se/four-ways-to-conduct-one-way-anovas-using-python/](https://www.marsja.se/four-ways-to-conduct-one-way-anovas-using-python/]) 链接
https://stackoverflow.com/questions/41648016
复制相似问题