我使用“ select * from link05m按类别,时间分组”进行查询,结果如下:
如何使用熊猫获得完全相同的结果?
# -*- coding: utf-8 -*-
import pandas as pd
import sqlalchemy
conn = sqlalchemy.create_engine('mysql://root@localhost/test?charset=utf8')
link05m = pd.read_sql_query("select * from link05m where time ='2015-12-24 10:00:00'", conn)
grpResult = link05m.groupby(['time', 'class'])
for r, g in grpResult:
print g # each g is make up of serveral Dataframes
最佳答案
如果您没有要执行的聚合(即,每对时间,每个班级都是唯一的),那么您就不需要做熊猫分组了。你应该试试 :
link05m = pd.read_sql_query("select * from link05m where time ='2015-12-24 10:00:00'", conn)
Result = link05m.set_index(['time', 'class'])