Bei mir schlägt Folgendes fehl mit: KeyError: „None of [Index(['v1', 'v2'], dtype='object')] are in the [index]"
Code: Select all
import pandas as pd
df = pd.DataFrame({'key':[1,1,1,2,3,2], 'v1': [1,4,6,7,4,9], 'v2':[0.3, 0.6, 0.4, .1, .2, .8]})
display(df)
def list_function(x):
#display(x)
all_values = x[['v1','v2']].drop_duplicates()
#display(all_values)
#result = all_values.to_json()
result = all_values.values
return result
display(df.groupby(['key']).apply(list_function))
df['list_result'] = df.groupby(['key']).transform(list_function)
df