I performed a groupby
which gives me a pd.Series
object. Something like this:
import pandas as pd
spanish = pd.Series(['uno', 'dos', 'tres'], ['one', 'two', 'three'])
>>> spanish
one uno
two dos
three tres
dtype: object
I have my original pd.DataFrame
containing one column who's indices match with the pd.Series
:
df = pd.DataFrame({'german': ['eins', 'zwei', 'drei'],
'english': ['one', 'two', 'three']},
index=[1, 2, 3])
>>> df
german english
1 eins one
2 zwei two
3 drei three
As can be seen above, the english
column matches with the indices from the spanish
series. I now want to add the spanish
values to df
. In other words, I want to get this:
>>> df
german english spanish
1 eins one uno
2 zwei two dos
3 drei three tres
Note: I tried to use loc
to assign spanish[df['english'][i]]
when iterating, but this process is extremely slow (my real DataFrame
has around 6 million entries). Furthermore, I can't use groupby.transform()
because I'm grouping on another DataFrame
. Lastly, I can't use indices (0, 1, 2) because they don't match either.
Thanks in advance.