【发布时间】:2019-10-04 08:35:49
【问题描述】:
我正在尝试在 python 中对独立性进行假设检验,但我的一个数据列(财务)具有浮点数据类型,而另一列(性别)具有对象数据类型。
我提出了以下假设: 何:财务不分性别 哈:财务状况与性别有关
我尝试直接使用输入,但出现以下错误: " 无法将字符串转换为浮点数:'female'"
import pandas as pd
import numpy as np
import scipy.stats as stats
test = np.array(df['Gender'],df['Finances'])
chi_sq_Stat, p_value, deg_freedom, exp_freq = stats.chi2_contingency(test)
print('Chi-square statistic %3.5f P value %1.6f Degrees of freedom %d' %(chi_sq_Stat, p_value,deg_freedom))
我期待一些 P 值来验证我的假设。
我附上了一张数据集的图片
【问题讨论】:
标签: python pandas chi-squared hypothesis-test statistical-test