| burdickjp |
07-10-2015 11:49 AM |
Data analysis and modification with Python
I've seen a number of tools for doing data analysis on here. Most are done with spreadsheets, which aren't conducive to large amounts of data. Others are written in Java, or .NET, which isn't bad, but isn't conducive to the end user wanting to learn not just what the tool does but how it does it.
Python is, by its nature, a human readable language, so I'd like to share with you how to do some data analysis in Python.
If you're running Linux you probably already have Python. We need the libraries called pandas and bokeh. I assume, since you are running Linux, that you know how to get these. I prefer using Python3.
If you're running anything else you can get an all-inclusive package called Anaconda which pulls everything in for you. Anaconda includes several environments for playing with Python. I prefer Spyder, as it has a variable explorer similar to MatLab. Think of it as being a MatLab environment, but better, because it's not MatLab.
Once you've got everything up, fire up Spyder. Throw this into the left pane and hit the green arrow. You'll want to edit line 13 to point to the log you'd like to use. Line 15 is the X axis of the graph. Line 16 is the Y axis.
Code:
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 9 22:06:52 2015
@author: jeff
"""
import pandas as pd
from bokeh.plotting import figure, HBox, output_file, show, VBox
output_file("graph.html")
logRaw = pd.read_csv('log.csv')
p1x = logRaw['time']
p1y = logRaw['RPM']
p1 = figure(tools="pan,wheel_zoom,box_zoom,reset,save", plot_width=1024, plot_height=600)
p1.scatter(p1x, p1y, size=1, color="red", alpha=0.5)
show(VBox(HBox(p1)))
I'll be updating this to include more awesome things like 3d graphs, etc. I'd eventually like to get MAF scaling tools and others ported to Python.
|