Say I have a series and dataframe like:
import pandas as pd
s = pd.Series([10,20,11,12,30,34],
index=["red","red","blue","blue","green","green"])
s.index.name="numbers"
df = pd.DataFrame({
"color":["red","green","blue","blue","red","green"],
"id":[1,2,3,4,5,6]})
I want to add the values in s to the column in df in the same order as they appear where the index of s is equal to df["color"] i.e
pd.some_function(df,s,left_on="color",right_index=True)
color id numbers
red 1 10
green 2 30
blue 3 11
blue 4 12
red 5 20
green 6 34
I have tried pd.merge, pd.join etc. but I simply cannot make it work (without looping over df, filtered by color, add the data from s and then concat it at the end)