Python Forum
do you know a code that will print all correlation values using numpty and panda?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
do you know a code that will print all correlation values using numpty and panda?
#1
Hi guys,

I'm new to python but am using to perform correlation analysis. Do you know of a code (im using numpty and panda) that will print all correlation values? This is my code:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
data = pd.read_csv('https://www.dropbox.com/s/cneg6eh0hznp8zo/atmospheric_temperature.csv?raw=1', index_col=0)
corr = data.corr()
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111)
cax = ax.matshow(corr,cmap='coolwarm', vmin=-1, vmax=1)
fig.colorbar(cax)
ticks = np.arange(0,len(data.columns),1)
ax.set_xticks(ticks)
plt.xticks(rotation=90)
ax.set_yticks(ticks)
ax.set_xticklabels(data.columns)
ax.set_yticklabels(data.columns)
plt.savefig(r'C:\Users\Austin\Desktop\atmpshperic_correlation.jpg', dpi=700)
plt.show()
it then produces a diagram where after I am able to type
"corr['Southsea_urban']['Residential']" in return it gives the correlation value of the specified variable.

Does any one know of a code that will allow me to print all correlation values at once? Thankyou.
Reply
#2
if you execute type(corr), you see that corr is a pandas.DataFrame. Pandas is heavily relies on Numpy, underlying
numpy array of a data frame can be accessed by .values attribute, e.g. corr.values. So, correlation matrix you are probably looking for is corr.values.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Different Correlation Coefficents with different Time Ranges giaco__mar 0 849 Sep-28-2022, 02:03 PM
Last Post: giaco__mar
  Adding a new column to a Panda Data Frame rsherry8 2 2,123 Jun-06-2021, 06:49 PM
Last Post: jefsummers
  How to filter data using a panda.DateFrame.loc pawlo392 1 2,651 May-27-2019, 08:47 PM
Last Post: michalmonday
  Cross-correlation between 2 planes in a 3D array Mark3232 2 4,595 May-16-2019, 09:46 AM
Last Post: Mark3232
  Make panda dataframe output pretty carstenlp 2 2,942 Jan-17-2019, 10:04 AM
Last Post: carstenlp
  Panda Dataframe Rounding Issue ab0217 5 7,256 Nov-06-2018, 10:15 PM
Last Post: ichabod801
  Help with correlation coefficient mattjb84 7 4,930 Jun-29-2018, 09:56 PM
Last Post: Larz60+
  Pandas dataframe: sum of exponentially weighted correlation matrices per row vvvcvvcv 1 3,261 May-29-2018, 01:09 AM
Last Post: scidam
  Mistake by correlation (x, y) Jack_Sparrow 2 2,723 May-10-2018, 02:23 PM
Last Post: volcano63
  Replacing values for specific columns in Panda data structure Padowan 1 14,668 Nov-27-2017, 08:21 PM
Last Post: Padowan

Forum Jump:

User Panel Messages

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