How To Replace Empty Values In One Column With Modified Values From Another Column?
Suppose I have the following dataframe called mapping_df: mapping | store_id --------|--------- a | 1 b | 2 | 3 c | 4 | 5 I would
Solution 1:
Try this guy:
df['mapping'] = df[['mapping', 'store_id']].apply(lambda x: x[0] if x[0] else 'edit-%d' % x[1], axis=1)
Solution 2:
If the blank entries in the mapping column are NaN
rather than just empty strings, the you could use the combine_first()
method:
df.mapping = df.mapping.combine_first('edit-' + df.store_id.astype(str))
Post a Comment for "How To Replace Empty Values In One Column With Modified Values From Another Column?"