I have a dataframe that contains a players form and appearances as floats for 5 seasons. My goal is to remove all players who have played less than 2 seasons.
Here is an example of the dataframe
Here is a link to the dataframe in a csv file on Google Drive
https://drive.google.com/file/d/1gfkPJlfoyl2sE2j8VqJYyqHJGBMXMfkO/view?usp=sharing
An example of players I would like to remove is Aaron Hughes who only played two seasons 13/14 & 12/13 or Abdoulaye Diaby who only played in the 14/15 season.
An example of a player I want to keep is Abdoulaye Keita who has played at least 4 seasons.
My expected output would be :
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
Any help would be greatly appreciated! Thanks
**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]
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]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.