I have a dataframe, which i applied lambda funciton with groupby, the lambda function generated two values as output, and the output is object data type.
I tried with output.to_frame().reset_index() and pd.DataFrame(output), neither really worked.
output.to_frame().reset_index() made the second column name 0, but i can’t display the second column with output.0. After output.to_frame().reset_index() looks like this:
What’s the best way to convert this object output from lambda function with groupby to a dataframe looks like this?
>Solution :
It would be better to do it upfront (before/when using groupby) but you can still try this :
out = df.join(pd.DataFrame(df.pop("0").tolist(), columns=["score", "value"]))
Output :
print(out)
id score value
0 a 1 2
1 b 4 5
2 c 6 7

