Python Pandas outlines for data analysis. This page outlines Pandas methods to create graphs. The data is [here][Pandas analysis].
Plotting with Pandas - Ice Cream Sales |
Outline
For correlation
Source code
The following outlines the Python code used:
import numpy as np import pandas as pd import sys import matplotlib.pyplot as plt xval = 'Violent Crime'; yval = 'Murder'; file='1111' ver=pd.read_csv("city.csv") plt.xlabel(xval) plt.ylabel(yval) plt.scatter(ver[xval],ver[yval]) plt.show() f2= file+".svg" plt.savefig(f2,format='SVG') f2= file+".png" plt.savefig(f2,format='PNG')
Data
The data used is [here]
date,IC,price,income,temp,Lag-temp,Year 1,0.386,0.27,78,41,56,0 2,0.374,0.282,79,56,63,0 3,0.393,0.277,81,63,68,0 4,0.425,0.28,80,68,69,0 5,0.406,0.272,76,69,65,0 6,0.344,0.262,78,65,61,0 7,0.327,0.275,82,61,47,0 8,0.288,0.267,79,47,32,0 9,0.269,0.265,76,32,24,0 10,0.256,0.277,79,24,28,0 11,0.286,0.282,82,28,26,1 12,0.298,0.27,85,26,32,1 13,0.329,0.272,86,32,40,1 14,0.318,0.287,83,40,55,1 15,0.381,0.277,84,55,63,1 16,0.381,0.287,82,63,72,1 17,0.47,0.28,80,72,72,1 18,0.443,0.277,78,72,67,1 19,0.386,0.277,84,67,60,1 20,0.342,0.277,86,60,44,1 21,0.319,0.292,85,44,40,1 22,0.307,0.287,87,40,32,1 23,0.284,0.277,94,32,27,1 24,0.326,0.285,92,27,28,2 25,0.309,0.282,95,28,33,2 26,0.359,0.265,96,33,41,2 27,0.376,0.265,94,41,52,2 28,0.416,0.265,96,52,64,2 29,0.437,0.268,91,64,71,2
Outline
The following is an outline of the code:
import numpy as np import pandas as pd import sys import matplotlib.pyplot as plt import statsmodels.api as sm xval = '5 GCEs or more'; yval = 'Leave'; file='1111' ver=pd.read_csv("eu.csv") plt.title(yval+' v ' + xval) plt.xlabel(xval) plt.ylabel(yval) plt.scatter(ver[xval],ver[yval]) axes = plt.gca() m, b = np.polyfit(ver[xval], ver[yval], 1) X_plot = np.linspace(axes.get_xlim()[0],axes.get_xlim()[1],100) plt.plot(X_plot, m*X_plot + b, '-') if (b>0): print yval,'=',round(m,2),' x ',xval,'+',round(b,2) else: print yval,'=',round(m,2),' x ',xval,round(b,2) print sm.OLS(ver[xval], ver[yval]).fit().summary() plt.show()