VLOOKUP IN PYTHON USING MERGE

Asked

Viewed 56 times

0

I have a dataframe called df with a column of countries in several languages and another dataframe called ct that I have a column with countries in several languages and another column with the same countries translated pro ingles. I want a datafram df column to have the translation of these countries into English consulted in the dataframe ct as if it were a vlookup. I tried to use the merge, but it is not searching properly.

ct = pd.DataFrame(country, columns=['RAW ORIGIN COUNTRY', 'ORIGIN COUNTRY', 'REGION'])

ct.rename(columns={'RAW ORIGIN COUNTRY':'Raw Origin'}, inplace=True)

df = pd.DataFrame(df, columns=['Raw Origin', 'Origin']

df['Origin'] = pd.merge(df, ct[['Raw Origin', 'ORIGIN COUNTRY']], on='Raw Origin', how='left')

quando eu exporto pro excel fica assim:
[![resultado final][1]][1]


  [1]: https://i.stack.imgur.com/ksari.jpg
  • In order to reproduce the error it would be appropriate to put at least 3 ct and df records.

  • The command pd.merge returns a dataframe. This makes the column 'Origin' of df be a dataframe and not series. That’s what you wanted?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.