# [Tutor] Python - Data Mining?

wormwood_3 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 *

def GraphData(time_and_count):
"""
Creates graph image of counts per time.
"""
# Set axis labels and their properties:
x = xlabel('Time')
setp(x, fontweight='bold')
y = ylabel('Count')
setp(y, fontweight='bold')
# Plot:
plotted = plot(time_and_count.keys(), time_and_count.values(), '--')
setp(plotted, marker='s')
title('Count over Time')
grid(True)
savefig('results.png', dpi=100)

# 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:
graphData(time_and_count)

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.

_______________________
Samuel Huckins

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?

Hi Nick,

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
cursor.execute('''
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 ?
cursor.execute(
"SELECT SUM(REPS) FROM WR WHERE EXER=?",
(srch,)
)

-Eric

On Sun, Jan 4, 2009 at 11:25 AM, Nick Scholtes <airchia at gmail.com> wrote:

Hi,
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,
Nick

--
Art: http://www.coroflot.com/bellsoffreedom

_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor

--
(e)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090104/39ec06c7/attachment.htm>
```

More information about the Tutor mailing list