Python Forum

Full Version: do you know a code that will print all correlation values using numpty and panda?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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.