我有一个数据框,其中包含玩家形式和外观作为浮动5个赛季。 我的目标是移除所有参加比赛不到2个赛季的球员。
以下是数据框的示例
以下是Google云端硬盘中csv文件中数据框的链接
https://drive.google.com/file/d/1gfkPJlfoyl2sE2j8VqJYyqHJGBMXMfkO/view?usp=sharing
我想删除的球员的一个例子是Aaron Hughes,他只打了两个赛季13/14& 12/13或Abdoulaye Diaby只参加了14/15赛季。
我想保留的球员的一个例子是至少打了4个赛季的Abdoulaye Keita。
我的预期输出是:
Players club 16/17 15/16 14/15 13/14 12/13 17/18
Form Apps Form Apps Form Apps Form Apps Form Apps Form Apps
0 Aaron Cresswell West Ham United 2.269231 26.0 3.108108 37.0 2.921053 38.0 0.000000 0.0 0.000000 0.0 2.400000 30.0
1 Aaron Hunt Hamburger SV 2.590909 22.0 2.136364 22.0 1.800000 15.0 3.741935 31.0 4.035714 28.0 2.500000 24.0
2 Aaron Lennon Everton 1.818182 11.0 2.760000 25.0 2.217391 23.0 2.555556 27.0 3.147059 34.0 1.913043 23.0
3 Aaron Ramsey Arsenal 2.173913 23.0 3.096774 31.0 3.241379 29.0 4.956522 23.0 1.833333 36.0 4.300000 20.0
4 Abdoul Camara En Avant de Guingamp 0.000000 0.0 2.235294 17.0 0.000000 0.0 1.500000 10.0 1.666667 15.0 0.000000 0.0
5 Abdoulaye Doucoure Watford 1.750000 20.0 4.558333 31.0 2.600000 35.0 3.750000 20.0 3.250000 4.0 3.000000 32.0
6 Abdoulaye Keita Le Havre AC 1.571429 21.0 1.000000 4.0 2.000000 5.0 1.200000 5.0 0.000000 0.0 0.00
任何帮助将不胜感激! 感谢
答案 0 :(得分:2)
**Here is a better solution to your question.**
df['count'] = 0
df.loc[df['16/17']['Apps']>9.0, 'count'] += 1
df.loc[df['15/16']['Apps']>9.0, 'count'] += 1
df.loc[df['14/15']['Apps']>9.0, 'count'] += 1
df.loc[df['13/14']['Apps']>9.0, 'count'] += 1
df.loc[df['12/13']['Apps']>9.0, 'count'] += 1
df[df['count']>3]
答案 1 :(得分:1)
x = 0
i = 0
array = []
while i < len(df):
if df['16/17']['Apps'][i] > 9.0:
x += 1
elif df['15/16']['Apps'][i] > 9.0:
x += 1
elif df['14/15']['Apps'][i] > 9.0:
x += 1
elif df['13/14']['Apps'][i] > 9.0:
x += 1
elif df['12/13']['Apps'][i] > 9.0:
x += 1
if x > 2:
array.append(True)
x = 0
else:
array.append(False)
x = 0
df[array]