[英]How do I identify the blank fields in the csv file in python?
I have a csv file with 5 columns:我有一个包含 5 列的 csv 文件:
1, 2312, "A", , 20
2, 8383, "B", "UK",
3, 3883, , , 45
where the columns represent id, customerId, customerName, customerAddress and customerAge.其中列表示 id、customerId、customerName、customerAddress 和 customerAge。 I want to put
0
at the place where the age is blank and ''
where the other string type attributes are blank.我想在年龄为空的地方放
0
,在其他字符串类型属性为空的地方放''
。 But I can't identify the blank field in python.但是我无法识别python中的空白字段。 I have tried doing some things like:
我试过做一些事情,比如:
len(row[4]) == 0
row[4] == ''
row[4] == None
repr(row[4]) == ''
but it didn't work.但它没有用。 What am I doing wrong?
我究竟做错了什么?
you want to use not
你想用
not
0
, None
, False
, ''
are all not True
0
, None
, False
, ''
都不是not True
if not row[4]:
you could also do你也可以这样做
bool(row[4])
which will return False
for all the above mentioned values这将为上述所有值返回
False
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.