Python: There are two datafames (namely df1 and df2 respectively) and we are required to 1. aggregate
Question:
Python: There are two datafames (namely df1 and df2 respectively) and we are required to
1. aggregate the 'points' based on the 'LocationID' and 'PlaceID' (they are actually the same thing but named differently somehow)
2. The aim of the 'agg_points' function is to take a dataframe, aggregate based on the 'points' column, and in the process clean up the indexing (as there are now less rows). Finally you will want to sort the current dataframe using the 'yolo' function provided.The key idea is to determine the total points for df1 and df2.
df1 ={'LocationId': [4,2,3,1],
'Chicago':[102,75,80,-3],
'Fairbanks':[45,5,-10,80],
'points':[67,87,90,75]
}
df2 ={'PlaceId': [2,4,1,3],
'NewYork':[18,83,74,-10],
'Boston':[32,58,-20,30],
'points':[62,80,73,25]
}
provided yolo function:
def yolo(df,key):
df123= df.sort_values(by=key,ascending=False, ignore_index=True)
return df123
Continue the following
def agg_points(df, id_name):
#to do (Please note that the yolo function will need be called in the agg_points function!!!!)
return
It might end up showing tables like this:
LocationID | Points |
PlaceID | points |
Modern Database Management
ISBN: 978-0133544619
12th edition
Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi