My Dataframe看起来像这样,我必须插入几行
Date AccessType PrePaidSubsRev
2013-11-01 1 584190
2013-11-01 2 0
2013-11-02 1 800020
2013-11-02 2 0
2013-11-03 1 705800
2013-11-03 2 0
2013-11-04 1 699930
2013-11-04 3 0
2013-11-04 2 0
2013-11-05 1 963270
2013-11-05 3 0
2013-11-05 2 0
2013-11-06 1 874530
2013-11-06 3 0
2013-11-06 2 0
2013-11-07 1 886005
2013-11-07 2 0
2013-11-08 1 1209300
2013-11-08 3 0
2013-11-08 2 0
2013-11-09 1 762560
2013-11-09 2 0
2013-11-10 1 489730
2013-11-10 2 0
对于缺少访问类型3的日期,我必须插入行 使用相同的日期和访问类型3和PrePaidSubsRev值为0.
如果有人有任何想法,请继续。
答案 0 :(得分:2)
>>> group = df.groupby(['Date','AccessType']).sum()
>>> temp = group.unstack()
>>> temp = temp.replace('nan',0)
>>> temp = temp1.stack()
>>> df = temp.reset_index()
这部分对我有用..谢谢