1

I have 2 dataframes that have some features in common but labeled differently. I'd like to create another dataframe with columns from both dataframes. The idea for the selection is that if

col1_df1 == col1_df2 & col2_df1 == col2_df2

then the row must be selected. I used this code but I don't know if it is working properly.

Can you help me?

pd.merge(data2_single_route, 
         data,left_on=['nodeid','res_time_start_s','res_time_end_s'],
         right_on=['nodeid','ts_start','ts_end'],how='inner')

Imagine that in dataframe 1 I have this:

10:00, 11:00, 1 , 'a'      
11:00 , 13:00 , 2, 'b'.   

In the dataframe 2 I have:

10:00 11:00 , 1 , '1500'  
11:00 , 12:00 , 2 , '6000'. 

The output that i want is:

10:00 , 11:00 , 1 , 'a' , 1500
anky
  • 74,114
  • 11
  • 41
  • 70
Andrea Fresa
  • 351
  • 2
  • 18
  • I do not understand the question. I think your code should display only the rows, where all the values from selected columns in data2_single_route equal those of data. – pnovotnyq May 25 '19 at 13:42
  • can you add a sample data and expected final dataframe please? – anky May 25 '19 at 13:43
  • @anky_91 imagine that in dataframe 1 i have this : 1)10:00, 11:00, 1 , 'a' 2)11:00 , 13:00 , 2, 'b'. In the dataframe 2 I have: 1)10:00 11:00 , 1 , '1500' 2)11:00 , 12:00 , 2 , '6000'. The output that i want is: 10:00 , 11:00 , 1 , 'a' , 1500 – Andrea Fresa May 25 '19 at 13:56
  • @AndreaFresa unfortunately comments are not the correct place for posting data, please update the question to include the examples and expected output. For help refer to: https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples – anky May 25 '19 at 13:57
  • @anky_91 modified – Andrea Fresa May 25 '19 at 14:02
  • I think your solution working nice, there is some problem? – jezrael May 25 '19 at 14:11
  • 1
    whats the output you are getting right now, it should be same as what you expected as @jezrael said your solution is correct – Ankit Kumar Namdeo May 25 '19 at 15:03

0 Answers0