0

There are to frames:

df2 = pd.DataFrame({'A1': ['A', 'B', 'C', 'D'],
                    'B1': ['E', 'F', 'G', 'H'],
                    'C1': ['I', 'J', 'K', 'L']})
df1 = pd.DataFrame({'B1': ['E', 'Q', 'P', 'F'],
                    'D1': [1, 2, 3, 4]})

Want to get the third:

df3 = pd.DataFrame({'A1': ['A', 'B', 'C', 'D'],
                    'B1': ['E', 'F', 'G', 'H'],
                    'C1': ['I', 'J', 'K', 'L'],
                    'D1': [1, 4, NaN, NaN]})

So if there is no such value at column B1 frame df1 in column B1 frame df2 (example 'G'), then there is NaN at D1 frame df3

Tried to merge df1 and df2 on B1, but values that are not presented at B1 of df2 are deleted from df1

0 Answers0