2016-07-17 107 views
1

我有这个巨大的csv文件列名为timedim,unblendedcost和更多。我在熊猫加载此,并试图做一些这相当于这个SQL语句,熊猫替代SQL语句

SELECT SUM(unblendedcost),从用途组timedim一天(timedim),其中的用法是我在数据库

我表确实尝试将CS​​V加载到数据库中,但它的行数为600万行。 任何帮助将非常感激

回答

1

它看起来像需要:

usages.groupby('timedim', as_index=False)['unblendedcost'].sum() 

如果timedimdtype为datetime与时间信息,使用:

usages.unblendedcost.groupby(df.timedim.dt.date, as_index=False).sum() 

样品:

import pandas as pd 

usages = pd.DataFrame({'timedim':[1,1,3,3], 
         'unblendedcost':[1,2,3,4], 
         'a':[7,8,9,8]}) 

print (usages) 
    a timedim unblendedcost 
0 7  1    1 
1 8  1    2 
2 9  3    3 
3 8  3    4 

print (usages.groupby('timedim', as_index=False)['unblendedcost'].sum()) 
    timedim unblendedcost 
0  1    3 
1  3    7 
+0

老兄,你是超级巨星。谢谢你太多了。 –

+0

请参阅示例,如果我的解决方案是你真正想要的。 – jezrael