【发布时间】:2014-08-07 21:40:06
【问题描述】:
我有一个 python 脚本,我想在其中读取一个 csv 文件,然后将此数据导入到 postgres 表中。不幸的是,csv 文件很乱,而且有很多空行。
arg = {
'date': date,
'store_id': row[0].strip(),
'price': row[1].strip(),
'description': row[2].strip()
}
cur.execute(
"""INSERT INTO
"Inventory"("date","store_id","price","description")
select %(date)s,
%(store_id)s,
%(price)s,
%(description)s
;""", arg)
我想跳过删除包含 store_id 和描述的空单元格的任何行 - 我该怎么做?
【问题讨论】:
标签: python postgresql csv