Answer the question
In order to leave comments, you need to log in
Duplicate in LEFT JOIN, how to fix?
Hello, Happy New Year everyone!
Confused. We need to join two tables, ratings and keywords , on the movieid columns , using a left join. To carry out in two ways: using LEFT JOIN in the query string to the database and using the merge method in pandas.
Result of join in pandas:
df2 = pd.read_sql('SELECT DISTINCT * FROM ratings', connect)
df3 = pd.read_sql('SELECT DISTINCT * FROM keywords', connect)
dm = df2.merge(df3, how='left', left_on='movieid', right_on='movieid')
Output: | userid | movieid | rating | timestamp | tags |
df1 = pd.read_sql('SELECT DISTINCT * FROM ratings
LEFT JOIN keywords ON ratings.movieid = keywords.movieid', connect)
Output: | userid | movieid | rating | timestamp | movieid | tags |
Answer the question
In order to leave comments, you need to log in
so you wrote "*"
this symbol is called asterisk and in this case stands for all join columns. and movieid, of course, is present in both tables. don't want them to be duplicated, specify explicitly which table it should fall into the result from by listing all required columns in the result set.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question