我有一个与此类似的pandas数据帧(我编写了一个示例,因为我无法共享数据)
raw_data = {'regiment': ['Nighthawks', 'Nighthawks', 'Dragoons', 'Dragoons', 'Scouts'],
'company': ['1st', '2nd', '1st', '2nd', '2nd'],
'thisValue': [1, 2, 3, 2, 7],
'total': [3, 3, 5, 5, 7]}
df = pd.DataFrame(raw_data, columns = ['regiment', 'company', 'thisValue', 'total'])
df
输出为:
regiment company thisValue total
0 Nighthawks 1st 1 3
1 Nighthawks 2nd 2 3
2 Dragoons 1st 3 5
3 Dragoons 2nd 2 5
4 Scouts 2nd 7 7
我想统计一个团每个值的数值。也就是说,我需要得到如下的数据帧:
regiment 1stCompanyValue 2nd_Company_Value total
Nighthawks 1 2 3
Dragoons 3 2 5
Scouts 0 7 7
我试着根据公司的价值观来分类,但不知道该怎么做。如何在熊猫身上做到这一点
我们可以利用^{} 、^{} 和^{} ,即
相关问题 更多 >
编程相关推荐