0

Can you please help me with this issue i am not able to get around in python pandas Basically i have 2 dataframes as below : df1 Table1 attached as pic

df2 Table2 attached as pic

i created a concatenate dataframe from the above two dataframes and got this result : df3=pd.concat([df1,df2],sort=False)

Table3 attached as pic

Now i have two columns in above df3 i.e. "a" and "az" which i want to merge as they are the same but have zeroes wherever 2nd dataframe doesnt have data. So is there a way to get a merged column of the two to represent same number i.e. wherever there are zeros in column "a" then it should fill it as the value in column "az" and vice versa.

Appreciate if you can please help. Thanks.

awansi
  • 1
  • 1
  • Take a look at this :https://stackoverflow.com/questions/19377969/combine-two-columns-of-text-in-dataframe-in-pandas-python. Hope it helps. – Raniere Soares Jun 05 '20 at 22:55

1 Answers1

0

Is this what you are looking for?

df2.columns = df1.columns 

df3 = pandas.merge(df1, df2, on='dt', how='left')

This would fill any values missing from df1 with df2.

Sy Ker
  • 2,047
  • 1
  • 4
  • 20
  • Thanks for your reply. But if i use merge function then its creating double values wherever df1 doesnt match with df2. Only few columns match like dt and a, but these two columns have different index. – awansi Jun 06 '20 at 11:44