EdwardJRoss/skeptric

pandas second most common value - another solution option

Closed this issue · 1 comments

I enjoyed the article on the second most common value calculation via method chaining. Below is another option, via pipe :

df.groupby('x').y.pipe(lambda df: pd.DataFrame({'frequency' : df.sum(), 'second' : df.nth(1)}))

link

Thanks! That suggestion is much better than anything I came up with!

I added it to the bottom of the post as the best solution and added a link to your Data Wrangling Blog.