我的简单程序从 Python 中提取数据库并存储在变量行中。
cursor = con.cursor()
cursor.execute("SELECT * FROM traffic")
#Retrieves data from SQL
rows = cursor.fetchall()
for row in rows:
row = list(row)
a = row[1:]
b = row[:-1]
print(a)
print(b)
现在我能够获得列表 a 和 b 中的月份和流量,例如 [1000L]
['January']
[100L]
['February']
[10430L]
['March']
[1500L]
['April']
[100L]
['May']
[1200L]
['June']
[800L]
['July']
[8000L]
['August']
[100000L]
['September']
现在我想绘制它,直方图和饼图。该行包含两个列:MOnth
和Traffic
。我想使用 Rpy2 将其转换为图表。我该怎么做?这是我的桌子:
month | traffic |
+-----------+---------+
| January | 1000 |
| February | 100 |
| March | 10430 |
| April | 1500 |
| May | 100 |
| June | 1200 |
| July | 800 |
| August | 8000 |
| September | 100000 |
+-----------+---------+