Q:

How to swap rows in 2 pandas dataframes which contain lists and have different size?

I have two Pandas dataframes, df1 and df2. Each dataframe has one column named 'Path'. Each row has a list. They are like this:
df1
Path
[OAK, ORD, FLL, PBG]
[OAK, SEA, FLL, PBG]
[OAK, AUS, FLL, PBG]
[OAK, LAS, FLL, PBG]
[OAK, LAX, FLL, PBG]
[OAK, DAL, FLL, PBG]
[OAK, MDW, FLL, PBG]
[OAK, BWI, FLL, PBG]

The df1 constructor is: 
{'Path': {0: ['OAK', 'ORD', 'FLL', 'PBG'],   2: ['OAK', 'SEA', 'FLL', 'PBG'],   4: ['OAK', 'AUS', 'FLL', 'PBG'],   6: ['OAK', 'LAS', 'FLL', 'PBG'],   8: ['OAK', 'LAX', 'FLL', 'PBG'],   10: ['OAK', 'DAL', 'FLL', 'PBG'],   12: ['OAK', 'MDW', 'FLL', 'PBG'],   14: ['OAK', 'BWI', 'FLL', 'PBG']}}

df2
Path
[OAK, DFW, FLL, PBG]
[OAK, JFK, FLL, PBG]
[OAK, MCI, FLL, PBG]
[OAK, PHX, FLL, PBG]
[OAK, DEN, FLL, PBG]
[OAK, HOU, FLL, PBG]
[OAK, ATL, FLL, PBG]

The df2 constructor is:
{'Path': {1: ['OAK', 'DFW', 'FLL', 'PBG'], 3: ['OAK', 'JFK', 'FLL', 'PBG'], 5: ['OAK', 'MCI', 'FLL', 'PBG'], 7: ['OAK', 'PHX', 'FLL', 'PBG'], 9: ['OAK', 'DEN', 'FLL', 'PBG'], 11: ['OAK', 'HOU', 'FLL', 'PBG'], 13: ['OAK', 'ATL', 'FLL', 'PBG']}}

One problem is that I have a different number of rows in my dataframes. I would like to swap the second element of each row of df1 with the second element of each row of df2. If there is no corresponding row, the row should not be modified or dropped. The desired output is:
df1
Path
[OAK, DFW, FLL, PBG]
[OAK, JFK, FLL, PBG]
[OAK, MCI, FLL, PBG]
[OAK, PHX, FLL, PBG]
[OAK, DEN, FLL, PBG]
[OAK, HOU, FLL, PBG]
[OAK, ATL, FLL, PBG]
[OAK, BWI, FLL, PBG]

df2
Path
[OAK, ORD, FLL, PBG]
[OAK, SEA, FLL, PBG]
[OAK, AUS, FLL, PBG]
[OAK, LAS, FLL, PBG]
[OAK, LAX, FLL, PBG]
[OAK, DAL, FLL, PBG]
[OAK, MDW, FLL, PBG]

How can I do it in Python?

A:

You can use combine_first() here after converting the series of list into a dataframe:
n=pd.DataFrame(df2['Path'].tolist())
m=pd.DataFrame(df1['Path'].tolist())
#----------------------------------------------------
df1_final=n[[1]].combine_first(m).dropna().agg(list,1)
df2_final=m[[1]].combine_first(n).dropna().agg(list,1)

print(df1_final)
print('\n')
print(df2_final)

0    [OAK, DFW, FLL, PBG]
1    [OAK, JFK, FLL, PBG]
2    [OAK, MCI, FLL, PBG]
3    [OAK, PHX, FLL, PBG]
4    [OAK, DEN, FLL, PBG]
5    [OAK, HOU, FLL, PBG]
6    [OAK, ATL, FLL, PBG]
7    [OAK, BWI, FLL, PBG]
dtype: object

0    [OAK, ORD, FLL, PBG]
1    [OAK, SEA, FLL, PBG]
2    [OAK, AUS, FLL, PBG]
3    [OAK, LAS, FLL, PBG]
4    [OAK, LAX, FLL, PBG]
5    [OAK, DAL, FLL, PBG]
6    [OAK, MDW, FLL, PBG]
dtype: object

