(Sep-25-2020, 05:06 AM)Milfredo Wrote: Have a problem with a function. I am reading from a data frame and when the condition is met, I am putting data into a two dimensional array. There are about 85 data points. Question is, must I pass the data points to the function or is there an easier way to accomplish this.As you use Pandas then there is probably a way to this with methods of Pandas DataFrame.
The you do not write code like this,but let Pandas 100's method handle this in the DataFrame.
(Sep-26-2020, 01:34 AM)Milfredo Wrote: Those factors will be used to get ratings for each horse based on their rank for each factorJust to give a example of what i mean.
import pandas as pd horses = { "Name": ["Goodspeed", "Horse killer9", "Speedy youngster"], "Year": ["7", "10", "5"], "Rating": ["8.8", "6.8", "5.2"], } df = pd.DataFrame(horses) print(df)
Output: Name Year Rating
0 Goodspeed 7 8.8
1 Horse killer9 10 6.8
2 Speedy youngster 5 5.2
So when have a data in a DataFrame can to all kind filter/ratings/rank stuff,and the as example send to a dictionary
df.to_dict()
or many other formats Json,Excel,csv,Sql,Html...ect when finish.Doing some stuff inside the DataFrame.
>>> df['Rating_Rank'] = df['Rating'].rank(ascending = 1) >>> df = df.set_index('Rating_Rank') >>> df Name Year Rating Rating_Rank 3.0 Goodspeed 7 8.8 2.0 Horse killer9 10 6.8 1.0 Speedy youngster 5 5.2 >>> >>> df = df.sort_index() >>> df = df.reset_index() >>> df Rating_Rank Name Year Rating 0 1.0 Speedy youngster 5 5.2 1 2.0 Horse killer9 10 6.8 2 3.0 Goodspeed 7 8.8 >>> >>> df.to_dict() {'Name': {0: 'Speedy youngster', 1: 'Horse killer9', 2: 'Goodspeed'}, 'Rating': {0: '5.2', 1: '6.8', 2: '8.8'}, 'Rating_Rank': {0: 1.0, 1: 2.0, 2: 3.0}, 'Year': {0: '5', 1: '10', 2: '7'}}