3

I have a csv file with 5 columns:

1, 2312, "A", , 20
2, 8383, "B", "UK", 
3, 3883, , , 45

where the columns represent id, customerId, customerName, customerAddress and customerAge. I want to put 0 at the place where the age is blank and '' where the other string type attributes are blank. But I can't identify the blank field in python. I have tried doing some things like:

  1. len(row[4]) == 0
  2. row[4] == ''
  3. row[4] == None
  4. repr(row[4]) == ''

but it didn't work. What am I doing wrong?

1
  • 1
    If possible, you should put your code up here Commented Sep 7, 2012 at 15:51

1 Answer 1

3

you want to use not

0, None, False , '' are all not True

if not row[4]:

you could also do

bool(row[4])

which will return False for all the above mentioned values

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.