【问题标题】:Student's t-test for the excel sheet using python使用 python 对 excel 表进行学生 t 检验
【发布时间】:2021-10-12 17:29:05
【问题描述】:

我有一个 Excel 表,其中包含 50 个地区 60 年的数据,如下所示:

年份 R1 R2 R3 .. .. .. .. .. .. .. .. R50

1951 66 45 22 .. .. .. .. .. .. .. .. 20

1952 54 .. .. .. .. .. .. .. .. .. .. .. .. .. 15

..

..

2010 51 33 .. .. .. .. .. .. .. .. .. .. 45

我想对 1951-1980 和 1981-2010 两个区间的数据进行 t 检验。并希望将每个区域的 t 和 p 值存储在 excel 或 csv 文件中。我该如何处理整个数据? 输入数据文件的链接是 https://docs.google.com/spreadsheets/d/1d3zpgUuGxTm-ncJQp-3sek9T6LKptY8a/edit?usp=sharing&ouid=100218359178484671666&rtpof=true&sd=true

【问题讨论】:

    标签: python pandas numpy scipy statistics


    【解决方案1】:
    from scipy.stats import ttest_ind
    import pandas as pd
    df=pd.read_excel("t-test_Data.xlsx")
    l=list()
    for i in df.columns[1:]:
        l.append(pd.DataFrame({i:ttest_ind(df[df.Year < 1981][i],df[df.Year >= 
    1981][i])}))
    d=pd.concat(l,axis=1)
    d.index=["statistic","p_value"]
    d.to_excel("t_test_statistic.xlsx")
    

    【讨论】:

    • 它有一个错误:'DataFrame' object has no attribute 'Year'
    • 运行第一个 df = df.reset_index()
    • 谢谢..我将 df.year 删除到 df.index 然后它工作了。
    猜你喜欢
    • 1970-01-01
    • 2014-05-28
    • 1970-01-01
    • 2014-06-04
    • 2016-03-28
    • 2013-06-02
    • 2021-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多