Really new to python and need a bit of help with a question I have to complete.
I need to find the average earned per time period (month/year), based on a user input for month (MM) and year (YYYY).
I have the inputs as follows:
year_value = int(input("Year (YYYY): "))
month_value = int(input("Month (MM): "))
My dataframe looks like this:
Race_Course Horse Name Year Month Day Amount_won_lost Won/Lost
Aintree Red Rum 2017 5 12 11.58 won
Punchestown Camelot 2016 12 22 122.52 won
Sandown Beef of Salmon 2016 11 17 20.0 lost
Ayr Corbiere 2016 11 3 25.0 lost
Fairyhouse Red Rum 2016 12 2 65.75 won
Ayr Camelot 2017 3 11 12.05 won
Aintree Hurricane Fly 2017 5 12 11.58 won
Punchestown Beef or Salmon 2016 12 22 112.52 won
Sandown Aldaniti 2016 11 17 10.0 lost
etc.
I have two problems:
- how do I group the data together based on the inputs and sum the Amount_won_lost values that match, and
- how do I make sure that when summing the values together that the value in Amount_won_lost is negative when Won/Lost = lost and stays positive for when Won/Lost = won
Any help would be very much appreciated! I've been stuck on this for a few hours and can't seem to figure it out.
The output should look something like this, but anything that prints the result would be perfect, I don't mind how it looks:
Year Month Amount_won_lost
2016 11 €-55.00