[英]pandas dataframe merge, ValueError, dtype mismatch
In [152] df1.dtypes
Out [152] id int64
user_id int64
area_ids object
areas object
birth_date object
birth_date_at datetime64[ns]
age_month int64
age_year float64
age_bin category
dtype: object
In [153] df2.dtypes
Out [153] review_meta_id int64
search_log_id int64
dtype: object
In [154] pd.merge(df2, df1, left_on="search_log_id", right_on="id")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
ValueError: Buffer dtype mismatch, expected 'Python object' but got 'long'
Exception ignored in: 'pandas._libs.lib.is_bool_array'
ValueError: Buffer dtype mismatch, expected 'Python object' but got 'long'
Out [154]
为什么是错误?
似乎age_bin
类别列导致了问题。 如果我省略数据,合并工作正常
数据如下所示
In [155] df1
Out [155]
id user_id area_ids areas birth_date birth_date_at age_month age_year age_bin
0 33722 3969 [1988] [파주/일산] 2012-12-10 2012-12-10 95 7.916667 8
1 33724 3969 [1988] [파주/일산] 2012-12-10 2012-12-10 95 7.916667 8
2 33725 3969 [1988] [파주/일산] 2012-12-10 2012-12-10 95 7.916667 8
3 33726 3969 [1995] [경기도전체] 2012-12-10 2012-12-10 95 7.916667 8
4 2833779 3969 [2878] [제주특별자치도] 2012-12-10 2012-12-10 95 7.916667 8
In [156] df2
Out [156]
review_meta_id search_log_id
0 1307 1346076
1 3282 1346076
2 4039 1346076
3 940 1346076
4 4148 1346076
问题出在旧的 pandas 版本中,这里是 pandas 0.21.0,升级到最后一个解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.