gpt4 book ai didi

python csv header

转载 作者:IT老高 更新时间:2023-10-28 21:12:53 28 4
gpt4 key购买 nike

我有一组 csv header ,我正在尝试与上传匹配。它并没有真正起作用。并非所有标题都是必需的——我只需要匹配文件中的内容即可。

reader = csv.DictReader(open(PathFile))
headers = reader.fieldnames
for header in sorted(set(headers)):
if (header == 'ip') or (header == 'IP'):
print "IP found in Header"

在这种情况下,找不到 IP。

for row in reader:
if row.get('IP'):
print "IP found in Row"

再也找不到了。我确实在这个网站上搜索过——有:

IP = row.get('IP', None)

那也没用。

这是我用于测试的文件:

Email, IP, Name, City, State, zip, country, garbage
ghfddgf@gfgs.com, 34.4.34.34,Mr GH, chicago, il ,60601, us,erw ewr
5t4g@fdsf.com, 34.45.23.34, Mr 5t,NY,NY,10101, us, er

最佳答案

根据您的编辑,您需要 skip the initial space在逗号之后。

应该这样做:

>>> reader = csv.DictReader(open(PathFile),skipinitialspace=True)

关于python csv header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1746489/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com