Python Forum
Do I have to pass 85 variables to function?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Do I have to pass 85 variables to function?
#7
(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 factor
Just 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'}}
Reply


Messages In This Thread
RE: Do I have to pass 85 variables to function? - by snippsat - Sep-26-2020, 10:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to pass encrypted pass to pyodbc script tester_V 0 874 Jul-27-2023, 12:40 AM
Last Post: tester_V
  How to print variables in function? samuelbachorik 3 919 Dec-31-2022, 11:12 PM
Last Post: stevendaprano
  User-defined function to reset variables? Mark17 3 1,668 May-25-2022, 07:22 PM
Last Post: Gribouillis
  How to pass variables from one class to another hobbyist 18 10,793 Oct-01-2021, 05:54 PM
Last Post: deanhystad
  Regex - Pass Flags as a function argument? muzikman 6 3,623 Sep-06-2021, 03:43 PM
Last Post: muzikman
  Possible to dynamically pass arguments to a function? grimm1111 2 2,207 Feb-21-2021, 05:57 AM
Last Post: deanhystad
  Pass by object reference when does it behave like pass by value or reference? mczarnek 2 2,572 Sep-07-2020, 08:02 AM
Last Post: perfringo
  print function help percentage and slash (multiple variables) leodavinci1990 3 2,500 Aug-10-2020, 02:51 AM
Last Post: bowlofred
  Pass integers to datetime.date function florian 3 2,735 Jul-18-2020, 04:43 AM
Last Post: scidam
  How to pass multiple arguments into function Mekala 4 2,468 Jul-11-2020, 07:03 AM
Last Post: Mekala

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020