I have a HC list in which every entry should have an ID, but some entries do not have an ID. I would like to fill those empty cells by combining the the first name column and the last name column. How would I go about this? I tried googling for fillna and the like but couldn't get it to work. What I want is basically this:
If hc["ID"] == "":
hc["ID"] = hc["First Name"] + hc["Last Name"]
Simply do the following: Select the cell with the formula and the adjacent cells you want to fill. Click Home > Fill, and choose either Down, Right, Up, or Left. Keyboard shortcut: You can also press Ctrl+D to fill the formula down in a column, or Ctrl+R to fill the formula to the right in a row.
Anyone who has used Excel for some time knows how to use the autofill feature to autofill an Excel cell based on another. You simply click and hold your mouse in the lower right corner of the cell, and drag it down to apply the formula in that cell to every cell beneath it (similar to copying formulas in Excel).
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"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With