Skip to content
Advertisement

what would be the most efficient way to do this in pandas

I’m trying to figure out the most efficient way to join two dataframes such as below.

I’ve tried pd.merge and maybe using the rank function but cannot seem to figure a way.

Thanks in advance

df1

JavaScript

What I’m trying to achieve is this

df2

JavaScript

Advertisement

Answer

You might want to use groupby with unstack as advised in this answer:

JavaScript
Advertisement