0

I have following two dataframes by common field 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)

I get following error, when I run 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

How would I join/merge by comm?

lpt
  • 931
  • 16
  • 35
  • Does this answer your question? [Trying to merge 2 dataframes but get ValueError](https://stackoverflow.com/questions/50649853/trying-to-merge-2-dataframes-but-get-valueerror) – Jaroslav Bezděk Apr 03 '20 at 18:40

1 Answers1

0

It is a slight variation of this SO post

vv.join(rr.set_index('comm'), on='comm', how='outer')

I have changed the first comm value of rr to (166.0467, 35.2363). So the two dataframes have at least one element in common. 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
above_c_level
  • 3,579
  • 3
  • 22
  • 37