Bottom Page

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.
Larz60+ wrote Mar-06-2019, 12:25 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

fixed for you this time, please use BBcode tags on all future posts. Thank you.
Quote
#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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to filter data using a panda.DateFrame.loc pawlo392 1 611 May-27-2019, 08:47 PM
Last Post: michalmonday
  Cross-correlation between 2 planes in a 3D array Mark3232 2 1,014 May-16-2019, 09:46 AM
Last Post: Mark3232
  Make panda dataframe output pretty carstenlp 2 376 Jan-17-2019, 10:04 AM
Last Post: carstenlp
  panda, excel - script pauses and doesn't continue running, no error message william 1 401 Nov-24-2018, 01:24 AM
Last Post: ichabod801
  Panda Dataframe Rounding Issue ab0217 5 1,009 Nov-06-2018, 10:15 PM
Last Post: ichabod801
  Help with correlation coefficient mattjb84 7 857 Jun-29-2018, 09:56 PM
Last Post: Larz60+
  Get max values based on unique values in another list - python Antonio 8 1,533 Jun-12-2018, 07:49 PM
Last Post: Mekire
  Pandas dataframe: sum of exponentially weighted correlation matrices per row vvvcvvcv 1 714 May-29-2018, 01:09 AM
Last Post: scidam
  How to group variables & check correlation of group variables wrt single variable SriRajesh 2 604 May-23-2018, 03:01 PM
Last Post: SriRajesh
  Mistake by correlation (x, y) Jack_Sparrow 2 651 May-10-2018, 02:23 PM
Last Post: volcano63

Forum Jump:


Users browsing this thread: 1 Guest(s)