Python:T测试df列上的ind循环
我的数据框架由会计变量和虚拟变量组成,虚拟变量允许我识别两种类型的公司。 我想对我的数据帧的每一列进行t检验,以便比较两种类型公司之间变量的平均值 目前,我已根据虚拟变量将df分为两个不同的df,并运行以下代码:Python:T测试df列上的ind循环,python,pandas,Python,Pandas,我的数据框架由会计变量和虚拟变量组成,虚拟变量允许我识别两种类型的公司。 我想对我的数据帧的每一列进行t检验,以便比较两种类型公司之间变量的平均值 目前,我已根据虚拟变量将df分为两个不同的df,并运行以下代码: for column_type1, column_type2 in zip(df_type1.columns[1:],df_type2.columns[1:]): print(ttest_ind(column_type1,column_type2, equal_var=Fals
for column_type1, column_type2 in zip(df_type1.columns[1:],df_type2.columns[1:]):
print(ttest_ind(column_type1,column_type2, equal_var=False, nan_policy='omit'))
但是,我得到了以下错误:
TypeError:无法使用灵活类型执行reduce
如果你知道如何解决这个问题或者有更好的方法,你的帮助是非常受欢迎的
谢谢
****编辑和解决方案****
我带来了我的问题,这里是代码
for column_type1, column_type2 in zip(df_type1,df_type2):
print(ttest_ind(df_type1[column_type1],df_type2[column_type2], equal_var=False, nan_policy='omit'))
错误是在zip中还是在调用测试中?这可能是一个很好的线索,请尝试分别运行每个语句。错误出现在对测试的调用中。循环似乎只获取列的标签,而不获取列中的值。然后,您遇到了错误,您是否尝试使用任意输入运行测试?如果这样做有效,那么您所要做的就是从数据生成该输入格式。
for column_type1, column_type2 in zip(df_type1,df_type2):
print(ttest_ind(df_type1[column_type1],df_type2[column_type2], equal_var=False, nan_policy='omit'))