Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Correlation
#1
I use the below code to produce the correlation and the p-value.

My questions are :
1. If there are many independent variables (Y) -- there are only 3 ind variables in the below example, how can I include all of them in the below code without hard code them?
2. How can I export the output to excel or csv file?



# Calculate the Pearson correlation 
import pingouin as pg
corr = pg.pairwise_corr(random_subset, columns=[['OBJ'], ['Acct_Tenure_1st_of_Month', 'H_XtraCare_Flag', 'Acct_Tenure']], method='pearson')
corr.sort_values(by=['p-unc'])[['X', 'Y', 'n', 'r', 'p-unc']].head()
X Y n r p-unc
2 OBJ Acct_Tenure 1000 0.082 0.009059
0 OBJ Acct_Tenure_1st_of_Month 1000 0.082 0.009206
1 OBJ H_XtraCare_Flag 1000 0.057 0.073851



Thanks.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I am getting a valueError. And not sure why? My goal is to visualize the correlation ReadytoCode 0 416 Dec-11-2023, 05:33 AM
Last Post: ReadytoCode
  Error in find pearson correlation function erneelgupta 1 1,810 Mar-01-2022, 03:41 PM
Last Post: stevendaprano
  How to increase the size of a png picture for the heatmap of the correlation? lulu43366 9 3,386 Oct-06-2021, 04:15 PM
Last Post: deanhystad
  How to remove a column or two columns in a correlation heatmap? lulu43366 3 5,081 Sep-30-2021, 03:47 PM
Last Post: lulu43366
  Computing correlation in audio files ryanblumenow 0 2,725 Jan-15-2020, 06:11 PM
Last Post: ryanblumenow
  Correlation of Incidents using time difference Rajhesh 1 1,777 Jun-27-2019, 03:44 PM
Last Post: Larz60+
  Correlation Matrix Problem Pmllz 0 1,989 Feb-02-2019, 10:19 PM
Last Post: Pmllz
  Correlation & Prediction - Help Danijel 2 2,759 Jul-12-2018, 11:08 PM
Last Post: Danijel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020