视频游戏是一款名为PUBG的FPS射击游戏。我想计算某人死于特定武器的次数。但是这些项目都在一栏中。
游戏killed_by
列出了玩家死亡的方式:
df.(['Grenade', 'SCAR-L', 'S686', 'Down and Out', 'M416', 'Punch', 'AKM',
'P92', 'Win94', 'M16A4', 'S12K', 'Hit by Car',
'death.WeapSawnoff_C', 'Kar98k', 'Tommy Gun', 'S1897', 'Bluezone',
'Micro UZI', 'P1911', 'SKS', 'Mini 14', 'Mk14', 'Falling', 'UMP9',
'P18C', 'Machete', 'Sickle', 'Groza', 'Crossbow', 'Drown', 'Vector',
'R1895', 'M249', 'Uaz', 'M24', 'VSS', 'Pan', 'AWM', 'RedZone',
'Motorbike', 'Buggy', 'death.ProjMolotov_DamageField_C', 'Dacia',
'DP-28', 'R45', 'Motorbike (SideCar)', 'death.Buff_FireDOT_C',
'Crowbar', 'AUG', 'Van', 'Pickup Truck', 'Aquarail', 'Boat',
'death.ProjMolotov_C', 'death.PG117_A_01_C', 'death.RedZoneBomb_C'], dtype=object).counter
使用这些值创建直方图。
df.killed_by.unique()
给出:
File "<ipython-input-38-042a4177bd4e>", line 1
df.(['Grenade', 'SCAR-L', 'S686', 'Down and Out', 'M416', 'Punch', 'AKM',
^
SyntaxError: invalid syntax
答案 0 :(得分:0)
df.([]).counter
会给您一个语法错误,因为您没有调用任何方法。
我不确切地知道你想通过那行代码实现什么,但是如果你想获得每种武器的出现,这可能是你可以做到的许多方法之一。
a = ['Grenade', 'SCAR-L', 'S686', 'Down and Out', 'M416', 'Punch', 'AKM',
'P92', 'Win94', 'M16A4', 'S12K', 'Hit by Car',
'death.WeapSawnoff_C', 'Kar98k', 'Tommy Gun', 'S1897', 'Bluezone',
'Micro UZI', 'P1911', 'SKS', 'Mini 14', 'Mk14', 'Falling', 'UMP9',
'P18C', 'Machete', 'Sickle', 'Groza', 'Crossbow', 'Drown', 'Vector',
'R1895', 'M249', 'Uaz', 'M24', 'VSS', 'Pan', 'AWM', 'RedZone',
'Motorbike', 'Buggy', 'death.ProjMolotov_DamageField_C', 'Dacia',
'DP-28', 'R45', 'Motorbike (SideCar)', 'death.Buff_FireDOT_C',
'Crowbar', 'AUG', 'Van', 'Pickup Truck', 'Aquarail', 'Boat',
'death.ProjMolotov_C', 'death.PG117_A_01_C', 'death.RedZoneBomb_C']
# or select the data by pandas indexing
from collections import Counter
print(Counter(a))