I have an empty DataFrame with columns but no rows. I want to apply groupby on it but it results in no columns. How to apply groupby and keep columns?
df = pd.DataFrame(data={'a':[], 'b': []})
df = df.groupby('a').apply(lambda g: g).reset_index(drop=True)
output:
Empty DataFrame
Columns: []
Index: []
df.index
Float64Index([], dtype='float64', name='a')