Python Pandas outlines for data analysis. This page outlines Pandas methods to create graphs. The data is [here][Pandas analysis].
Plotting with Pandas - Telnet |
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]
No,Mac SRC,Mac Dest,IP Src,IP Dest,IP Proto,TTL,TCP Src,TCP Dest,UDP Src,UDP Dest,Len 1,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,74 2,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,78 3,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,66 4,00:0c:29:0f:71:a3,ff:ff:ff:ff:ff:ff,,,,,,,,,42 5,00:50:56:f5:2e:f3,00:0c:29:0f:71:a3,,,,,,,,,42 6,00:0c:29:0f:71:a3,00:50:56:f5:2e:f3,192.168.75.132,192.168.75.2,17,128,,,1034,53,85 7,00:50:56:f5:2e:f3,00:0c:29:0f:71:a3,192.168.75.2,192.168.75.132,17,128,,,53,1034,135 8,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,87 9,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,69 10,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,74 11,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,93 12,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,101 13,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,66 14,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,123 15,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,219 16,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,111 17,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,66 18,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,408 19,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,257 20,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,66 21,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 22,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 23,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,66 24,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 25,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 26,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,66 27,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 28,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 29,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,66 30,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 31,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 32,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,66 33,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 34,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 35,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,66 36,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 37,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 38,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 39,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 40,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 41,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 42,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,66 43,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 44,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 45,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 46,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 47,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 48,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 49,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,66 50,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 51,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 52,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 53,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 54,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,66 55,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,68 56,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,78 57,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,66 58,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 59,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,66 60,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 61,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,66 62,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,68 63,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,66 64,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,68 65,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,66 66,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,68 67,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,66 68,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,69 69,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,69 70,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,72 71,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,76 72,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,66 73,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,313 74,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,66 75,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,287 76,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,66 77,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 78,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 79,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 80,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 81,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 82,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 83,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,66 84,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,68 85,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,862 86,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,66 87,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 88,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 89,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 90,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 91,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 92,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 93,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,67 94,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,67 95,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,68 96,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,66 97,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,66 98,00:50:56:c0:00:08,00:0c:29:0f:71:a3,192.168.75.1,192.168.75.132,6,128,3714,23,,,66 99,00:0c:29:0f:71:a3,00:50:56:c0:00:08,192.168.75.132,192.168.75.1,6,128,23,3714,,,66
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()