93728

[code]

    import numpy as np
    import pandas as pd
    df_maize = pd.read_csv("PSD online data maize.csv", thousands=',')]
    df_maize.corr()
    
[/code]

相関係数の計算まではできましたが以下の検定でエラーが起きました

[code]

    import pandas as pd
    import matplotlib.pyplot as plt
    import seaborn as sns
    from scipy.stats import spearmanr
    bs=df_maize['Beginning Stocks'].values
    es=df_maize['Ending Stocks'].values
    p_value=df_maize.corr[0]
    TypeError                                 Traceback (most recent call last)
    <ipython-input-11-9b62ddc60036> in <module>
          1 bs=df_maize['Beginning Stocks'].values
          2 es=df_maize['Ending Stocks'].values
    ----> 3 p_value=df_maize.corr[0]
    
    TypeError: 'method' object is not subscriptable
    
[/code]


CC BY-SA 4.0
2023-02-06T05:08:41.920
93727
2023-02-06T05:59:54.920
56639
question
python pandas numpy scipy
無相関検定をしたいのですがやりかたを教えてください


`p-value` を求めるなら `scipy.stats.pearsonr()` を使うとよいかと。

[code]

    import pandas as pd
    from scipy.stats import pearsonr
    
    df = pd.DataFrame({'A': range(5),
                       'B': [x**2 for x in range(5)],
                       'C': [x**3 for x in range(5)]})
    
    p_value = df.corr(method=lambda x, y: pearsonr(x,y)[1])
    print(df)
    print(p_value)
    
[/code]

**dataframe**

A | B | C  
---|---|---  
0 | 0 | 0  
1 | 1 | 1  
2 | 4 | 8  
3 | 9 | 27  
4 | 16 | 64  
  
**p-value**

| A | B | C  
---|---|---|---  
A | 1 | 0.00993072 | 0.0341674  
B | 0.00993072 | 1 | 0.00174922  
C | 0.0341674 | 0.00174922 | 1


CC BY-SA 4.0
2023-02-06T05:59:54.920
93728
2023-02-06T05:59:54.920
47127
93727
answer