Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
2108 views
Kernel: Python 3 (Anaconda)
import numpy as np import scipy as sp import pandas as pd import matplotlib.pyplot as plt import seaborn as sns %matplotlib inline
data = pd.read_csv('longley.csv', header=0, index_col=0) data.info()
<class 'pandas.core.frame.DataFrame'> Int64Index: 16 entries, 1947 to 1962 Data columns (total 7 columns): GNP.deflator 16 non-null float64 GNP 16 non-null float64 Unemployed 16 non-null float64 Armed.Forces 16 non-null float64 Population 16 non-null float64 Year 16 non-null int64 Employed 16 non-null float64 dtypes: float64(6), int64(1) memory usage: 1.0 KB
data.head(5)
data['Employed'].corr(data['Population'], method='pearson')
0.96039057159437557
import numpy as np import matplotlib.pyplot as plt import statsmodels.api as sm hie_data = sm.datasets.randhie.load_pandas() corr_matrix = np.corrcoef(hie_data.data.T) sm.graphics.plot_corr_grid([corr_matrix] * 8, xnames=hie_data.names) plt.show()
/ext/anaconda3/lib/python3.5/site-packages/statsmodels/compat/pandas.py:56: FutureWarning: The pandas.core.datetools module is deprecated and will be removed in a future version. Please use the pandas.tseries module instead. from pandas.core import datetools
Image in a Jupyter notebook
import numpy as np import matplotlib.pyplot as plt import statsmodels.graphics.api as smg hie_data = sm.datasets.randhie.load_pandas() corr_matrix = np.corrcoef(hie_data.data.T) smg.plot_corr(corr_matrix, xnames=hie_data.names) plt.show()
Image in a Jupyter notebook
hie_data
<class 'statsmodels.datasets.utils.Dataset'>