我试图通过将值与其他数据帧匹配,在现有数据帧中创建一个新列
index | rating | movie_id | movie_title
--------------------------------------------
0 | 5 | 100 | Inception
1 | 4 | 101 | Starwars
index | rating | movie_id
------------------------------
0 | 3.9 | 101
1 | 4.7 | 100
index | rating | movie_id | movie_title
--------------------------------------------
0 | 3.9 | 101 | Starwars
1 | 4.7 | 100 | Inception
pd.merge(movies , recommendations, on ='movie_id', how ='left')
This doesn't make sense because both dataframes are not of same sizes. Recommendation dataframe's size is given by user through console.
你可以试试这个:
输出:
在
df1
中创建一个匹配行的字典作为键,并将要传输的值作为字典值使用
df.map()
方法将字典中的值映射到df2
相关问题 更多 >
编程相关推荐