我有两个具有以下信息的数据框:
>>> ratings.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5 entries, 0 to 4
Data columns (total 4 columns):
id 5 non-null int64
movie_id 5 non-null object
rating 5 non-null object
account_id 5 non-null int64
dtypes: int64(2), object(2)
memory usage: 240.0+ bytes
>> movies.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 296 entries, 0 to 295
Data columns (total 9 columns):
id 296 non-null int64
description 296 non-null object
genre 296 non-null object
imdb_url 296 non-null object
img_url 296 non-null object
title 296 non-null object
users_rating 296 non-null object
year 296 non-null object
movie_id 296 non-null object
dtypes: int64(1), object(8)
memory usage: 20.9+ KB
尽管公用列具有相同的数据类型,但显示:
>>> pd.merge(ratings,movies)
Empty DataFrame
Columns: [id, movie_id, rating, account_id, description, genre,
imdb_url, img_url, title, users_rating, year]
Index: []
先前关于stackoverflow的答案建议检查数据类型的相似性。但是,由于我的数据类型相同,该错误的解决方案是什么?
答案 0 :(得分:0)
这是使用['id','movie_id']进行的内部联接,因此如果生成的DF为空,则两个数据帧中的id和movie_id的组合均不匹配。比较两个数据帧中不同的“ id”和“ movie_id”组合
movies.groupby(['id', 'movie_id'])['id'].count()
ratings.groupby(['id', 'movie_id'])['id'].count()