Python Pandas outlines for data analysis. This page outlines Pandas methods to create graphs. The data is [here][Pandas analysis].
Plotting with Pandas - Syslog |
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:ab:01:53,00:50:56:ab:4a:4e,192.168.100.7,50.31.164.186,6,128,8682,443,,,609 2,00:50:56:ab:4a:4e,00:50:56:ab:01:53,50.31.164.186,192.168.100.7,6,238,443,8682,,,60 3,00:50:56:ab:4a:4e,00:50:56:ab:01:53,50.31.164.186,192.168.100.7,6,238,443,8682,,,117 4,00:50:56:ab:01:53,00:50:56:ab:4a:4e,192.168.100.7,50.31.164.186,6,128,8682,443,,,54 5,00:50:56:ab:4a:4e,00:50:56:ab:01:53,192.168.99.7,192.168.100.7,6,63,51044,514,,,74 6,00:50:56:ab:01:53,00:50:56:ab:4a:4e,192.168.100.7,192.168.99.7,6,128,514,51044,,,54 7,00:50:56:ab:45:c3,01:00:5e:00:01:18,192.168.46.7,224.0.1.24,17,2,,,42,42,60 8,00:50:56:ab:45:c3,ff:ff:ff:ff:ff:ff,192.168.46.7,192.168.46.255,17,128,,,138,138,243 9,00:50:56:ab:4a:4e,00:50:56:ab:01:53,192.168.100.254,192.168.100.7,17,64,,,514,514,196 10,00:50:56:ab:4a:4e,00:50:56:ab:01:53,192.168.100.254,192.168.100.7,17,64,,,514,514,129 11,00:50:56:ab:63:c4,ff:ff:ff:ff:ff:ff,192.168.2.7,192.168.2.255,17,128,,,138,138,249 12,00:50:56:ab:4a:4e,00:50:56:ab:01:53,192.168.100.254,192.168.100.7,17,64,,,514,514,196 13,00:50:56:ab:4a:4e,00:50:56:ab:01:53,192.168.100.254,192.168.100.7,17,64,,,514,514,127 14,00:50:56:ab:01:53,00:50:56:ab:4a:4e,192.168.100.7,50.31.164.186,6,128,8682,443,,,609 15,00:50:56:ab:4a:4e,00:50:56:ab:01:53,50.31.164.186,192.168.100.7,6,238,443,8682,,,60 16,00:50:56:ab:4a:4e,00:50:56:ab:01:53,50.31.164.186,192.168.100.7,6,238,443,8682,,,117 17,00:50:56:ab:01:53,00:50:56:ab:4a:4e,192.168.100.7,50.31.164.186,6,128,8682,443,,,54 18,00:50:56:ab:2a:67,ff:ff:ff:ff:ff:ff,192.168.30.7,192.168.30.255,17,128,,,138,138,243 19,00:50:56:ab:4a:4e,00:50:56:ab:01:53,192.168.100.254,192.168.100.7,17,64,,,514,514,196 20,00:50:56:ab:4a:4e,00:50:56:ab:01:53,192.168.100.254,192.168.100.7,17,64,,,514,514,129 21,00:50:56:ab:01:53,00:50:56:ab:4a:4e,192.168.100.7,50.31.164.186,6,128,8682,443,,,609 22,00:50:56:ab:4a:4e,00:50:56:ab:01:53,50.31.164.186,192.168.100.7,6,238,443,8682,,,60 23,00:50:56:ab:4a:4e,00:50:56:ab:01:53,50.31.164.186,192.168.100.7,6,238,443,8682,,,117 24,00:50:56:ab:01:53,00:50:56:ab:4a:4e,192.168.100.7,50.31.164.186,6,128,8682,443,,,54 25,00:50:56:ab:45:c3,ff:ff:ff:ff:ff:ff,192.168.46.7,192.168.46.255,17,128,,,138,138,249 26,00:50:56:ab:4a:4e,00:50:56:ab:01:53,192.168.100.254,192.168.100.7,17,64,,,514,514,196 27,00:50:56:ab:4a:4e,00:50:56:ab:01:53,192.168.100.254,192.168.100.7,17,64,,,514,514,129 28,00:50:56:ab:63:5e,ff:ff:ff:ff:ff:ff,192.168.36.7,192.168.36.255,17,128,,,138,138,243 29,00:50:56:ab:4a:4e,00:50:56:ab:01:53,192.168.100.254,192.168.100.7,17,64,,,514,514,197 30,00:50:56:ab:4a:4e,00:50:56:ab:01:53,192.168.100.254,192.168.100.7,17,64,,,514,514,129 31,00:50:56:ab:4a:4e,00:50:56:ab:01:53,192.168.100.254,192.168.100.7,17,64,,,514,514,131 32,00:50:56:ab:4a:4e,00:50:56:ab:01:53,192.168.100.254,192.168.100.7,17,64,,,514,514,131 33,00:50:56:ab:4a:4e,00:50:56:ab:01:53,192.168.100.254,192.168.100.7,17,64,,,514,514,131 34,00:50:56:ab:4a:4e,00:50:56:ab:01:53,192.168.100.254,192.168.100.7,17,64,,,514,514,125 35,00:50:56:ab:4a:4e,00:50:56:ab:01:53,192.168.100.254,192.168.100.7,17,64,,,514,514,197 36,00:50:56:ab:4a:4e,00:50:56:ab:01:53,192.168.100.254,192.168.100.7,17,64,,,514,514,127 37,00:50:56:ab:01:53,00:50:56:ab:4a:4e,192.168.100.7,50.31.164.186,6,128,8682,443,,,609 38,00:50:56:ab:4a:4e,00:50:56:ab:01:53,50.31.164.186,192.168.100.7,6,238,443,8682,,,60 39,00:50:56:ab:4a:4e,00:50:56:ab:01:53,50.31.164.186,192.168.100.7,6,238,443,8682,,,117 40,00:50:56:ab:01:53,00:50:56:ab:4a:4e,192.168.100.7,50.31.164.186,6,128,8682,443,,,54
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()