I am cleaning data. In the code below, I am using the str.title
function to capitalize words. Then I check to see if they are empty, and if so I write something. But then I have to assign the row back to a variable, but I am a bit confused on that.
for row in moma:
gender = row[5]
#capitalize gender column
gender = gender.title()
#check to see if column is empty
if not gender:
gender = 'Gender Unknown/Other'
row[5] = gender
for row in moma:
Nationality = row[2]
Nationality = Nationality.title()
if not Nationality:
Nationality = 'Nationality Unknown'
row[2] = Nationality
Example data:
['Duplicate of plate from folio 11 verso (supplementary suite, plate 4) from ARDICIA', 'Pablo Palazuelo', 'Spanish', '(1916)', '(2007)', 'Male', '1978', 'Prints & Illustrated Books']
['Tailpiece (page 55) from SAGESSE', 'Maurice Denis', 'French', '(1870)', '(1943)', 'Male', '1889-1911', 'Prints & Illustrated Books']