Pandas 是否难以添加具有条件的新列?
我试着做多重分组,同时也向新列添加计数 我的输入文件Pandas 是否难以添加具有条件的新列?,pandas,python-2.7,Pandas,Python 2.7,我试着做多重分组,同时也向新列添加计数 我的输入文件 OrderDate Region Rep Item Units Unit Cost Total ---------------------------------------------------------- 1/6/18 East Jones Pencil 95 1.99 189.05 1/23/18 Central Kivell Binder 50 19.99
OrderDate Region Rep Item Units Unit Cost Total
----------------------------------------------------------
1/6/18 East Jones Pencil 95 1.99 189.05
1/23/18 Central Kivell Binder 50 19.99 999.50
2/9/18 Central Jardine Pencil 36 4.99 179.64
2/26/18 Central Gill Pen 27 19.99 539.73
3/15/18 West Sorvino Pencil 56 2.99 167.44
4/1/18 East Jones Binder 60 4.99 299.40
4/18/18 Central Andrews Pencil 75 1.99 149.25
4/18/18 West Jones Pencil 75 1.99 149.25
我正试着做我喜欢的事
Region Rep Count same/diff
-------------------------------
east jones 2 2-same
jones
central Kivell 4 >3 differnce
Jardine
Gill
Andrews
West Sorvino 2 2-different
West jones1
我的代码:
df1 = pd.read_excel(excel_path, sheet_name = 'SalesOrders', index_col=0)
df3 = (df1.groupby('Region')['Rep'].value_counts())
print(df3)
请帮我做这个。谢谢
在rep列中,基于我已完成分组的区域,以了解rep值。如果ReP成员是相同的,那么2个相同的人,考虑中心区域有4个不同的人工作,所以我大于3。< /P>列<代码>相同/差异/代码>意味着什么?您想对数据做什么?REP列中的两个相同值及其相反的值,那么
4>3差异是什么意思?
如果超过3个相同或不同的值,则必须大于3无法理解。。。