0
#takes group object applys a group by civil twilight groupby then takes the avearge of several columns
funct_day_night = lambda x: [x['Severity'].mean(), x["Distance(mi)"].mean(), x['Severity'].count()]
group_group_df = group_df.apply(lambda g_df : g_df.groupby('Civil_Twilight').apply(funct_day_night))
group_group_df

enter image description here

I want to turn all of the output on the right into columns. Please link me to the documentation I was not sure what to even look up. It might be best to answer the question in two parts one with fixing the function above and the other with fixing the out put either solution will work for me.

The data set I used was: https://www.kaggle.com/sobhanmoosavi/us-accidents

Juan Ramos
  • 179
  • 1
  • 10
  • 1
    Does this answer your question? [Pandas split column of lists into multiple columns](https://stackoverflow.com/questions/35491274/pandas-split-column-of-lists-into-multiple-columns) – rpanai Jan 23 '20 at 19:12
  • My data comes out as a pandas series when I print it it shows it like that for some reason – Juan Ramos Jan 23 '20 at 19:29
  • I don't think that method will work – Juan Ramos Jan 23 '20 at 19:30
  • [explode?](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.explode.html) – Ben Pap Jan 23 '20 at 22:28
  • @JuanRamos What do you mean by _My data comes out as a pandas series when I print it it shows it like that for some reason_? If you can share a proper [mcve], we should be able to find an all around better way of doing this. – AMC Jan 24 '20 at 02:09
  • I was able to figure it out using `pivot_table` I used the parameter `aggfunc = [np.mean, Count]` . So I avoided using `groupby` – Juan Ramos Jan 24 '20 at 17:38

0 Answers0