I'm trying to merge three dataframes together on a specific column – 'mal_id', and keep getting errors like syntax invalid or dataframe is ambiguous.
Attempt:
fave_movies:
|user_id |mal_id|rating|
|--------|------|------|
|1 |5000 |6.0 |
|1 |2467 |10.0 |
|1 |50 |7.0 |
anime_df:
|mal_id. |genres |title |
|--------|----------|------|
|1 |['Comedy']|001 |
|1 |['Comedy']|001 |
|1 |['Comedy']|001 |
filled_data:
|mal_id |rating |title |
|--------|----------|------|
|1 |10.0. |001 |
|2 |9.0 |001 |
|1 |4.0 |001 |
I have tried this method and keep getting invalid syntax errors:
df = fav_movies.merge((animes_df, on = 'mal_id') & ( filled_data, on = 'mal_id'))
df.head(3)
output:
File "<ipython-input-30-13c300cde0ef>", line 1
df = fav_movies.merge((animes_df, on = 'mal_id') & ( filled_data, on = 'mal_id'))
^
SyntaxError: invalid syntax
I also tried this method:
df = fav_movies.merge(animes_df, filled_data, on = 'mal_id')
df.head(3)
output:
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I just wondering whether I merge the three columns right or is there other efficient way to merge these dataframe together.
EDIT:
This is the result I want to get from merge the three dataframe:
|user_id | mal_id | rating | genres | title | favorite |
|--------|----------|-------|----------|-------|----------|
|1 | 29978 | 6.0 |['Comedy']| 001 | 0.0 |
|36 | 29978 | 5.0 |['Drama'] | Shin Shirayuki-hime Densetsu Prétear | 1.5 |
|70 | 29978 | 5.0 |['Comedy']| Uchuu Kaizoku Captain Herlock | 4.5 |