0

I am new to pandas and trying to join 2 dataframes with no shared column and different indexes:

df_1

id  name  date
1   John  2019-11-27
2   Dave  2019-11-27
...

df_2

id-new  name-new  date-new          type
11      John2     2019-11-27 23:54  Google
22      Dave2     2019-11-27 22:15  Bing
33      Mary      2019-11-11 15:31  Yahoo
...

Desired output df_3:

id  name  date       id-new  name-new  date-new          type
1   John  2019-11-27 11      John2     2019-11-27 23:54  Google
2   Dave  2019-11-27 22      Dave2     2019-11-27 22:15  Bing
                     33      Mary      2019-11-11 15:31  Yahoo
...

I have tried df_1.merge(df_2) but it states that it requires a common column which I do not have.

pd.concat produces NAN values:

              Date                   Date-DB                                              Gclid                              Gclid_DB Provider Provider-DB click_type
0      2019-11-240                       NaT  EAIaIQobChMI2t6D4MqB5gIVA9bACh0BvwK-EAAYAyAAEg...                                   NaN  test2         NaN        NaN
1      2019-11-240                       NaT  CjwKCAiAzuPuBRAIEiwAkkmOSJ7WSwoG9veQ-jKXYi5Fyx...                                   NaN  test2         NaN        NaN
2      2019-11-240                       NaT  EAIaIQobChMIkdObncWB5gIVFZzVCh245Aq0EAAYASAAEg...                                   NaN  test2         NaN        NaN
3      2019-11-240                       NaT  CjwKCAiAzuPuBRAIEiwAkkmOSHDEAo0jtVHXRWOr3Rh1Yj...                                   NaN  test2         NaN        NaN
4      2019-11-240                       NaT  EAIaIQobChMI-ZenkNCB5gIVAx6tBh0gOg9GEAAYASAAEg...                                   NaN  test2         NaN        NaN
...            ...                       ...                                                ...                                   ...      ...         ...        ...
12741          NaN 2019-11-25 23:59:40+00:00                                                NaN  7d904da7-cd77-428c-a0d3-1fbe3c3c992d      NaN     test2      gclid
12742          NaN 2019-11-25 23:59:44+00:00                                                NaN  690aa2e3-de06-4f96-82bc-aed9c7ed16dc      NaN     test2      gclid
12743          NaN 2019-11-25 23:59:45+00:00                                                NaN  7a3ebeee-bfad-4f9d-931c-234d30ad8b52      NaN   test3      gclid
12744          NaN 2019-11-25 23:59:50+00:00                                                NaN  0e907d6f-0bf5-4fbc-8b03-8f0e0d73487b      NaN   test1      gclid
12745          NaN 2019-11-25 23:59:59+00:00                                                NaN  463bec78-b7c1-4a15-9f81-c163ece05a45      NaN     test2      gclid

Thank you for your suggestions.

Jonas Palačionis
  • 4,591
  • 4
  • 22
  • 55
  • I get an empty dataframe when I try merging this way. Only the headers gets added next to each other. – Jonas Palačionis Nov 27 '19 at 07:57
  • I am trying to add a dataframe with 1000 rows with 3 columns and dataframe with 2000 rows and 4 columns with no matching columns. What I would expect is to have a dataframe with 3000 rows and 7 columns. The 1000 rows from the first dataframe would be empty in my final output. I just dont want them to get stacked below each other, I want them to stack next to each other like just dragging 2 tables next to each other with excel. – Jonas Palačionis Nov 27 '19 at 08:04
  • Trying your code I get this error - `ValueError: Shape of passed values is (9740, 7), indices imply (8400, 7)` – Jonas Palačionis Nov 27 '19 at 08:04
  • It produces Nan values, edited my question. – Jonas Palačionis Nov 27 '19 at 08:10
  • hmmm, `df = pd.concat([df_1.reset_index(drop=True), df_2.reset_index(drop=True)], axis=1)` ? – jezrael Nov 27 '19 at 08:15
  • Yes, I've dropped them separately and then it worked: ```join_ho.reset_index(drop=True, inplace=True) connection_global.reset_index(drop=True, inplace=True) result_final = pd.concat([connection_global,join_ho],axis=1,ignore_index=True)``` – Jonas Palačionis Nov 27 '19 at 08:17
  • Super, added answer to dupe with explanation – jezrael Nov 27 '19 at 08:18

0 Answers0