0

I have two dataframes df1 and df2 with different shapes (number of rows and columns differ).

df1

ticketid descp alertname

1 3000 nsp 2 1000 rsp 3 5000 gsp

df2

ticketid vol prd technology

1 30 scom soft
3 45 dess hard 6 34 scom soft 7 35 scom hard

I need to combine these two dataframes based on ticketid column. the new dataframe must have all values from df1 and whatever matches in df2(based on ticketid) those rows also need to be added.

I want the new dataframe to be like this

ticketid descp alertname vol prd technology

1 3000 nsp 30 scom soft 3 5000 gsp 45 dess hard

How to do this in pandas`

lakshith
  • 11
  • 4
  • You can use `left` join on `ticketid` column @lakshith – pc_pyr Mar 30 '20 at 12:29
  • Yes I did. it throws the following error. ValueError: The column label 'TicketID' is not unique. – lakshith Mar 30 '20 at 12:36
  • df1.merge(df2,on="TicketID",how="left"). I tried left, outer, inner...but all ends up throwing error - ValueError: The column label 'TicketID' is not unique. – lakshith Mar 30 '20 at 12:37
  • Try `df=pd.merge(df1,df2,on="ticketid",how='left')`. You have provided the output dataframe, if you want to do a left join, then row `2 1000 rsp` from df1 should also essentially be a part of the output @lakshith – pc_pyr Mar 30 '20 at 12:57
  • yes tried. Same error - ValueError: The column label 'TicketID' is not unique. – lakshith Mar 30 '20 at 13:43
  • This `df=pd.merge(df1,df2,on="ticketid",how='left')` works fine, I tried it with your dataframe! – pc_pyr Mar 30 '20 at 13:56

0 Answers0