I define my code to find correlation between 'day' and 'sales' each store by using this code
def store_corr(store_num):
subset= df[df['store']== store_num]
subset= subset[['day','dollar_sales']]
subset_corr = subset.corr()
corr_val = subset_corr.iloc[0,1]
return corr_val
And Next step is running for loop each store like this
store = df.store.unique()
for i in store:
corre = store_corr(i)
print(corre)
But All I need are columns that provide store_num and corr for each store, so How I can coding to get output like this:
store | corre |
---|---|
1 | 0.26 |
2 | 0.12 |
3 | -0.96 |
Thank you