【发布时间】:2013-09-18 12:44:50
【问题描述】:
我有 2 个数据框:
restaurant_ids_dataframe
Data columns (total 13 columns):
business_id 4503 non-null values
categories 4503 non-null values
city 4503 non-null values
full_address 4503 non-null values
latitude 4503 non-null values
longitude 4503 non-null values
name 4503 non-null values
neighborhoods 4503 non-null values
open 4503 non-null values
review_count 4503 non-null values
stars 4503 non-null values
state 4503 non-null values
type 4503 non-null values
dtypes: bool(1), float64(3), int64(1), object(8)`
和
restaurant_review_frame
Int64Index: 158430 entries, 0 to 229905
Data columns (total 8 columns):
business_id 158430 non-null values
date 158430 non-null values
review_id 158430 non-null values
stars 158430 non-null values
text 158430 non-null values
type 158430 non-null values
user_id 158430 non-null values
votes 158430 non-null values
dtypes: int64(1), object(7)
我想使用 pandas 中的 DataFrame.join() 命令将这两个 DataFrame 连接成一个数据帧。
我尝试了以下代码行:
#the following line of code creates a left join of restaurant_ids_frame and restaurant_review_frame on the column 'business_id'
restaurant_review_frame.join(other=restaurant_ids_dataframe,on='business_id',how='left')
但是当我尝试这个时,我得到了以下错误:
Exception: columns overlap: Index([business_id, stars, type], dtype=object)
我对 pandas 很陌生,就执行 join 语句而言,我不知道我做错了什么。
任何帮助将不胜感激。
【问题讨论】:
-
关于 pandas 合并的相关、更广泛的主题:Pandas Merging 101.
标签: python pandas dataframe merge left-join