0

I have two df's: one has a date in the first column: all dates of the last three years and the second column are names of participants, other columns are information.

In the second df, I have some dates on which we did tests in the first column, then second column the names again and more columns information.

I would like to combine the two dateframes that in the first dataframe the information from the second will be added but for example if we did one test on 2-9-2020 and the same test for the same person on 16-9-2022 then from 2-9-202 until 16-9-2022 i want that variable and after that the other.

I hope it's clear what i mean.

i tried data.merge(data_2, on='Date' & 'About') but that is not possible to give two columns for on.

3 Answers3

0

Please, I would be nice if you can provide and example. I would try this.

import pandas as pd
new_df = pd.merge(data,names_participants, on = ['Date'], how = 'left')

I would validate if everything is right regarding the date format as well.

Selknam_CL
  • 34
  • 4
0

With Python and Pandas, you can join on 2 variables by using something like: df=pd.merge(df,df2,how="left",on=['Date','About']) # can be how="left" or "inner","right","outer"

0

I think you had the right idea, but not quite the right syntax. Does the following work for your situation?

import pandas as pd

new_df = pd.merge(data, data2, on = ["Date", "About"], how = "left")
mh0w
  • 91
  • 7