[英]Joining two data frames that appear to be same type gives error 'ValueError: You are trying to merge on object and int64 columns'
[英]ValueError: You are trying to merge on object and int64 columns error when joining by cooridnates
我通過公共字段comm
關注了兩個數據幀
DataFrame I (vv)
V_Id object
V_Time object
comm object
dtype: object
V_Id V_Time comm
0 1234 2020-02-02-10-15-20 (166.0467, 35.2363)
1 1234 2020-02-02-10-15-22 (166.047, 35.2363)
2 1234 2020-02-02-10-15-23 (166.0473, 35.2363)
3 1234 2020-02-02-10-15-25 (166.0475, 35.2363)
DataFrame II (rr)
R_Id object
comm object
dtype: object
R_Id comm
0 One (166.0467, 35.2371)
1 One (166.0468, 35.2371)
2 One (166.0468, 35.2371)
當我運行vv.join(rr, on=['comm'])
時出現以下錯誤
ValueError: You are trying to merge on object and int64 columns. If you wish to proceed you should use pd.concat
我將如何通過comm
加入/合並?
這是這個SO 帖子的一個輕微變化
vv.join(rr.set_index('comm'), on='comm', how='outer')
我已將 rr 的第一個 comm 值更改為 (166.0467, 35.2363)。 所以這兩個數據框至少有一個共同點。 Output:
V_Id V_Time comm R_Id
0.0 1234.0 2020-02-02-10-15-20 (166.0467, 35.2363) One
1.0 1234.0 2020-02-02-10-15-22 (166.047, 35.2363) NaN
2.0 1234.0 2020-02-02-10-15-23 (166.0473, 35.2363) NaN
3.0 1234.0 2020-02-02-10-15-25 (166.0475, 35.2363) NaN
NaN NaN NaN (166.0468, 35.2371) One
NaN NaN NaN (166.0468, 35.2371) One
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.