0

I have a data frame with a date index in the form of YYYY-MM-DD and another data frame with normal indexing, they both have the same number of rows and i want to join the two data frames. Join and merge functions don't work, concat function changes the date format to a date time format by adding hours-mins-sec and there are many null values in the table. So how can i join the two data frames?

this is the code i used: pd.concat([HK4, adjusted_data], axis=1, join='outer', ignore_index=False)

1"dataset with date time index"

2"dataset with normal indexing" 3"concatenated dataset"

laadom
  • 1
  • 1
  • 2
    Could you show some actual data for both dataframes? Show the code you have tried with proper syntax so we can reproduce the problem. – JQadrad May 21 '20 at 00:56
  • @JQadrad i updated the question with pictures of the data frames – laadom May 21 '20 at 02:20

1 Answers1

0

Try reset index in DataFrame with index YYYY-MM-DD.

import pandas as pd
# create first dataframe
d1 = {'dt': ['2020-01-02', '2020-05-05'], 'col1': [1, 2], 'col2': [3, 4]}
df1 = pd.DataFrame(data=d1).set_index('dt')
# create second dataframe
d2 = {'col3': ['hello', 'world'], 'col4': ['how', 'to']}
df2 = pd.DataFrame(data=d2)
# concatenate dataframes
df3 = pd.concat([df1.reset_index(), df2], axis=1)

merge result

shmakovpn
  • 751
  • 9
  • 10