1 回答
TA贡献1777条经验 获得超10个赞
用于slice(None)选择该级别的所有内容。slice(None) 使您免于陈述更深层次的内容。这意味着他们
df=df.pivot_table(index=['publisher', 'month_leadgen'], columns=['month_payment'], values=['revenue']).reset_index()
print(df)
publisher month_leadgen revenue
month_payment 2019-01 2019-02 2019-03
0 facebook 2019-01 60.0 NaN NaN
1 facebook 2019-02 NaN 150.0 NaN
2 facebook 2019-03 NaN NaN 450.0
3 google 2019-01 85.0 NaN NaN
4 google 2019-02 NaN 250.0 NaN
5 google 2019-03 NaN NaN 150.0
选择
df.loc[:, (slice(None), '2019-01')]
revenue
month_payment 2019-01
0 60.0
1 NaN
2 NaN
3 85.0
4 NaN
5 NaN
添加回答
举报