Fill empty cells in column with value of other columns

You can use loc and a boolean mask if NaN then:

hc.loc[hc["ID"].isnull(),'ID'] = hc["First Name"] + hc["Last Name"] 

otherwise for empty string:

hc.loc[hc["ID"] == '','ID'] = hc["First Name"] + hc["Last Name"]

As an alternative, you can also use fillna() if not dealing with strings:

hc['ID'].fillna(hc['First Name'] + hc['Last Name'], inplace=True)

docs: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.fillna.html

Tags:

Python

Pandas

Na