My simple program extracts the database from Python and store in the variable row.
cursor = con.cursor() cursor.execute("SELECT * FROM traffic")#Retrieves data from SQLrows = cursor.fetchall() for row in rows:row = list(row)a = row[1:]b = row[:-1]print(a)print(b)
Now that I am able to get the month and traffic in list a and b like [1000L]
['January']
[100L]
['February']
[10430L]
['March']
[1500L]
['April']
[100L]
['May']
[1200L]
['June']
[800L]
['July']
[8000L]
['August']
[100000L]
['September']
Now I want to plot, histogram and piechart out of it.
The row contains two coloumns: MOnth
and Traffic
. I want to convert this into the chart using Rpy2. How do I do it? Here's my table:
month | traffic |
+-----------+---------+
| January | 1000 |
| February | 100 |
| March | 10430 |
| April | 1500 |
| May | 100 |
| June | 1200 |
| July | 800 |
| August | 8000 |
| September | 100000 |
+-----------+---------+