I have two different files containing the same number of columns but different lengths, i.e,
file1.txt
1650,A,1,1,1
1650,A,1,1,1
1650,A,1,1,1
1650,B,2,2,2
1650,B,2,2,2
1650,B,2,2,2
1650,B,2,2,2
1650,B,2,2,2
file2.txt
1650,A,3,3,3
1650,A,3,3,3
1650,A,3,3,3
1650,A,3,3,3
1650,A,3,3,3
1650,B,4,4,4
1650,B,4,4,4
I want to concatenate both of them using pandas such that the result is as follows:
1650,A,1,1,1,3,3,3
1650,A,1,1,1,3,3,3
1650,A,1,1,1,3,3,3
1650,A,NaN,NaN,NaN,3,3,3
1650,A,NaN,NaN,NaN,3,3,3
1650,B,2,2,2,4,4,4
1650,B,2,2,2,4,4,4
1650,B,2,2,2,NaN,NaN,NaN
1650,B,2,2,2,NaN,NaN,NaN
1650,B,2,2,2,NaN,NaN,NaN
I use the following codes but it seems it does not work properly:
df1 = read_data('file1')
df2 = read_data('file2')
result = pd.merge_ordered(df1,df2, how='outer', on=['a', 'b'])
How to solve this problem?