import numpy as np
import pandas aspd
df_maize=pd.read_csv("PSD online data maize.csv", thousands=',')]
df_maize.corr()
I was able to calculate the correlation coefficient, but there was an error in the following test
import pandas as pd
import matplotlib.pyplot asplt
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>
1bs = df_maize ['Beginning Stocks'].values
2es=df_maize ['Ending Stocks'].values
---->3p_value=df_maize.corr[0]
TypeError: 'method' object is not subscriptable
If you want p-value
, you should use scipy.stats.pearsonr()
.
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=lambdax, y:pearsonr(x,y)[1])
print(df)
print(p_value)
dataframe
p-value
© 2024 OneMinuteCode. All rights reserved.