I have a pandas DataFrameGroupBy object which I would like to cast to a normal dataframe. Now I know that I can use:
df_g.apply(lambda x: x)
But why is that needed? Considering that apply's are typically expensive in Pandas. Is there a better solution? I don't see any eye-watering performance penalties for my test case (since I don't have too many columns) so it might be fine. Just curious :)
Sample code:
import pandas as pd
df = pd.DataFrame({'a': [1,2,3,4,5], 'b': ["a", "a", "a", "b", "b"]})
df_g = df.groupby(by='b')
df_again = df_g.apply(lambda x:x)
Regards, Niklas