列联表分析程序,以卢淑华书上的例子为例
生活随笔
收集整理的這篇文章主要介紹了
列联表分析程序,以卢淑华书上的例子为例
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
#---------------------------------------------------------#
#--- * 我的 列聯(lián)表數(shù)據(jù)構(gòu)造 * ----#
#--------------------------------------------------------#like = np.array([[1, 2, 3], [1, 2, 3], [1, 2, 3]])
freq = np.repeat(like, [20, 5, 2, 10, 20, 10, 2, 35, 20])
freqagegrp = [1] * (20+5+2) + [2] * (10 + 20+10) + [3] * (2 +35 +20)
agegrpdf2 = pd.DataFrame(zip(agegrp,freq), columns=['agegrp', 'freq'])df2
df_c = pd.crosstab(df2['agegrp'], df2['freq'])
df_cdf_c.index = ['old', 'mid', 'young']
df_c
df_c.columns = ['xiqu', 'gewu', 'qiusai']
df_cdf2.keys()a = np.array(pd.crosstab(index = df2['agegrp'], columns = df2['freq']))
aimport scipy.stats as statsstats.chi2_contingency(a)import seaborn as sns
df2['agegrp']
df2['freq']
df2fig, ax = plt.subplots()
sns.countplot(x = df2['agegrp'], hue = df2['freq'])
ax.set_xticklabels(['old', 'mid', 'young'])
plt.legend(['xiqu', 'gewu', 'qiusai'])
結(jié)果如圖
?
?
?
總結(jié)
以上是生活随笔為你收集整理的列联表分析程序,以卢淑华书上的例子为例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MBT LAW反坦克导弹
- 下一篇: pandas to_json转换时强制中