Python:如何检查CSV文件中的单元格是否为空? [英] Python: How to check if cell in CSV file is empty?

查看:1813
本文介绍了Python:如何检查CSV文件中的单元格是否为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Python阅读的CSV文件,如果第一列为空,我希望程序跳过该行.我该怎么办?

I have a CSV file that I'm reading in Python and I want the program to skip over the row if the first column is empty. How do I do this?

现在我有:

with open('testdata1.csv', 'rU') as csvfile:
        csvreader = csv.reader(csvfile)
        for row in csvreader:
            if row[0] = null:
                #?????

我该如何:1)检查CSV中是否有空单元格;和2)告诉读者跳过该行?

How do I: 1) Check for empty cells in the CSV; and 2) tell the reader to skip the row?

谢谢大家.

推荐答案

with open('testdata1.csv', 'r') as csvfile:
    csvreader = csv.reader(csvfile)
    for row in csvreader:
        print(row)
        if row[0] in (None, ""):
             print("12")

参考: 如何检测以Python方式丢失CSV文件中的字段?

这篇关于Python:如何检查CSV文件中的单元格是否为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆