熊猫:groupby / aggregation / sum

时间:2018-01-26 16:16:29

标签: python python-3.x pandas-groupby

我有一个 DataFrame

ID_client l   date  l   contact
--------------------------------------
1          2017/01/01      email
1          2017/01/02      mail
1          2017/01/03      email
1          .........
1          2017/06/06      sms 
2          ......          tel 
2                          tel 
3
.
etc      until 2017/31/31 etc 

我希望有2个DataFrame,这是第一年只有一行,每个联系人的总和在不同的列中分开,每月最后一行:

1)

id l email l sms l tel l mail
----------------------------
1    40       20   30    50
2    20       30    40   50 
2  ........................
3 ..............etc 

2)

id l date_month l email l sms l tel l email
--------------------------------------------------
1    2017/01      20       10    5    2
1    2017/02      ..............
.
2    2017/01   .............
2    2017/02  ................
.
etc

我试过

Df.set_index("date")
Df["contact"].resample("m")

或者

Df.groupby(df["date", "I'd_client"])[contact].Count

或者我尝试创建另一个数据框

df2=Df.groupby(df.index)
Df2=[["contact"]]
df2.apply(lambda x : x.count())

我试过了:

Df.set_index("date") Df["contact"].resample("m")

或者

Df.groupby(df["date", "I'd_client"])[contact]. Count

或者我尝试创建另一个数据框

df2=Df.groupby(df.index)Df2 = [[“contact”]] df2.apply(lambda x:x.count())

但它没有给我我想要的东西!!

0 个答案:

没有答案