Merge on one column or another
You can use pd.Series.map
with fillna
a few times:
ticker_map = df2.set_index('cik')['Ticker']
df1['ticker'] = df1['cik0'].map(ticker_map)\
.fillna(df1['cik1'].map(ticker_map))\
.fillna(df1['cik2'].map(ticker_map))
This, however, is a bit tedious. You can define a function to do this iteratively:
def apply_map_on_cols(df, cols, mapper):
s = df[cols[0]].map(mapper)
for col in cols[1:]:
s = s.fillna(df[col].map(mapper))
return s
df1['ticker'] = df.pipe(apply_map_on_cols,
cols=[f'cik{i}' for i in range(3)],
mapper=df2.set_index('cik')['Ticker'])