Nick M. Nick M. - 3 months ago 12
Python Question

How to delete a row if one of the cells is empty

Here is the spreadsheet :

Color Name Size
red Apple large
green Apple small
orange Orange small
pea Green super small


Here I replace all instances of Apple with Apple_Object and delete any name that isn't apple:

for x in name:
if 'Apple' not in name:
name = name.replace(x, '')


for x in name:
name = name.replace('Apple', 'Apple_Object')



sheet.write(name):


Color Name Size
red Apple_Object large
green Apple_Object small
orange small
pea super small


How do I delete all rows with no name?

Desired output:

Color Name Size
red Apple_Object large
green Apple_Object small


Thanks!

Answer

You are replacing the value of apple for nothing

for x in list:
  if 'Apple' not in list:
     list = list.replace(x, '')

but you should be eliminating the current row

for x in list:
  if 'Apple' not in list:
     del list[index]
Comments