I need this code to go over a dictionary (many columns of a dataframe) and find the most unique combination values in the dimensions of a dataframe.
For example: in movies DF, if I send the columns genre and director + the measure Score to the function I'll get the max value from all unique combinations in genre and director:
def bi_robot(dataframe, dimensions, measure):
t = {}
for d in dimensions:
du = dataframe[d].unique()
t[d] = du[0]
for v in t:
key = v
value = [t[v]]
dataframe = dataframe.loc[dataframe[key].isin(value)]
stat = dataframe[measure].max()
print('---------------------')
print(t, end = '')
print(' Max:' + "{:.2f}".format(stat))
print('---------------------')
return t
df = df_rp.copy(deep = True)
filters = ['genre', 'director']
measure = 'score'
df = bi_robot(df, filters, measure)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…