[Tutor] Python - Data Mining?
wormwood_3 at yahoo.com
Sun Jan 4 21:07:27 CET 2009
I have done some data analysis work with Python, mostly with MySQL databases. Just as easy as the examples Eric mentioned with SQLite. All depends on what database you have to work with. Did you have any in mind or just wondering about data mining and Python in general?
Regarding graphing, I have had great luck with using pylab ( http://www.scipy.org/PyLab ). Here is a simple example to create graphs of a thing being counted per unit:
# Grab the needed module:
from pylab import *
Creates graph image of counts per time.
# Set axis labels and their properties:
x = xlabel('Time')
y = ylabel('Count')
plotted = plot(time_and_count.keys(), time_and_count.values(), '--')
title('Count over Time')
# Make a test dictionary of counts per time:
time_and_count = dict(enumerate('4 5 3 4 6 7 8 9 3'.split()))
# Make a graph:
If all goes well, you should end up with a file "results.png" in the dir you ran this script. There is a LOT more you can do with pylab, but this sort of function should get you going for simple graphs.
Homepage - http://samuelhuckins.com
Tech blog - http://dancingpenguinsoflight.com/
Photos - http://www.flickr.com/photos/samuelhuckins/
AIM - samushack | Gtalk - samushack | Skype - shuckins
From: Eric Dorsey <dorseye at gmail.com>
To: Nick Scholtes <airchia at gmail.com>
Cc: tutor at python.org
Sent: Sunday, January 4, 2009 2:32:12 PM
Subject: Re: [Tutor] Python - Data Mining?
I don't know about the graphing portion of your question, but yes Python does interact very well with databases. I have been working on a workout tracking program the last two months or so, and I'm new to programming. I'd highly recommend SQLite as a built-in database solution. I know it's included in Python version 2.5 which is what i'm currently running. You can call it at the top of your program with "import sqlite3", then you can run queries and create tables, etc.
Here is some example code of SQLite usage in my program:
#create the database, or connect if it already exists
conn = sqlite3.connect('workoutstats.db')
#create a variable called cursor to use, since its easier than typing out conn.cursor() all the time..
cursor = conn.cursor()
#create a table
CREATE TABLE WR (id INTEGER PRIMARY KEY, reps SMALLINT(1000),
weight SMALLINT(1000), exer VARCHAR(30), date DATE)
#query the WR table, feeding it the 'srch' variable which fills in where the SQL has a ?
"SELECT SUM(REPS) FROM WR WHERE EXER=?",
On Sun, Jan 4, 2009 at 11:25 AM, Nick Scholtes <airchia at gmail.com> wrote:
I'm still very, very new to Python and programming. I was wondering if anyone can point me in the right direction.
As I gradually learn Python, one of the things I want to be able to do is take a database, run queries and extract information and then graph that information visually to see patterns in the data. Where should I start?
Does Python do this? If not, what language is used for this?
Thank you very much,
Tutor maillist - Tutor at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor