Reputation: 11
I have a spreadsheet with 7 thousands player stats from Pro Evolution Soccer and i wanna get the percentage of incidence of each value of each attribute based on his position.
Something like:
Striker - Attack = 99: 1.3%; 98: 1.8%; 97: 3.5%;...
CenterBack - Attack = 99: 0.002%; 98: 0.003%; 97: 0.006%;...
Then I will create a random player generator based on this parameters.
Upvotes: 1
Views: 139
Reputation: 613
I think np.random.choice does the trick if you want to sample directly:
import numpy as np
# generate some stats (ie your soccer values)
np.random.seed(1)
soccer_stats = np.random.normal(0, 1, size=100)
# sample from them
sampled_stat = np.random.choice(soccer_stats)
print(sampled_stat)
-0.8452056414987196
give a look at np.histogram to observe the distribution you're sampling from. collections.Counter is nice for looking at the distribution of non numerical data (maybe your soccer players names?)
Upvotes: 1
Reputation: 1188
To answer your question directly: when you want to know percentiles of a certain distribution you can use numpy
import numpy as np
strikerAttackValueList=np.random.randint(0,100,1000)#example of stats list
percentile50=np.percentile(strikerAttackValueList,50)
But this is as much a math statistics question as a coding question.
First step would be to check how the values in Pro Evolution Soccer are distributed. This could be normal, uniform,.. (https://en.wikipedia.org/wiki/List_of_probability_distributions ) with a certain average and standard deviation. To know that, import the stat you want to study and do something like this: http://www.insightsbot.com/blog/WEjdW/fitting-probability-distributions-with-python-part-1
Then, to generate random player stats you can use either random or numpy (example assuming uniform distribution between 0 and 100):
import random
strikerAttackValue=random.randint(0,100)
print(strikerAttackValue)
import numpy as np
strikerAttackValue=np.random.randint(0,100)
print(strikerAttackValue)
Upvotes: 2