提问人:Aarit Singh 提问时间:11/4/2023 最后编辑:Mark TolonenAarit Singh 更新时间:11/4/2023 访问量:42
Python 似乎无法正确识别输入
Python does not seem to recognise inputs properly
问:
我正在做一个基本项目,在 Python 中扫描 CSV 文件以查找已购买产品的特定标识符。以下是相关列的销售电子表格的前几行:
Saturday Pass - 4/20
Saturday Pass - 4/20
Workshop Pass (4/19-4/21)
Friday 4/19 Concert @ 8pm
Friday 4/19 Concert @ 8pm
Sunday Pass - 4/21
Friday 4/19 Concert @ 8pm
Saturday 4/20 Concert @ 8pm
Friday 4/19 Concert @ 8pm
Panel Discussion
Friday Pass - 4/19
Panel Discussion
Panel Discussion
Friday Pass - 4/19
Friday Pass - 4/19
Panel Discussion
Friday Pass - 4/19
Panel Discussion
Saturday 4/20 Concert @ 8pm
Panel Discussion
Panel Discussion
Panel Discussion
Panel Discussion
Friday 4/19 Concert @ 8pm
Friday 4/19 Concert @ 8pm
Saturday 4/20 Concert @ 8pm
Panel Discussion
Friday Pass - 4/19
Workshop Pass (4/19-4/21)
这是我的代码:
import csv
from collections import Counter
#open file to read
with open('test.csv', mode =
'r',) as f:
#define the dataset
readed = csv.reader(f)
for row in readed:
#define the searched string
numbertofind = "Workshop Pass (4/19-4/21)\n"
#search for string
if numbertofind == row[17]:
print("found")
else:
#print details if not found
print(row[17])
我对 Python 相当陌生,我尝试过改变我的方法,而是遍历一列,但我找不到有效的方法。
如果有人对此有解决方案,或者有办法使这段代码变得更好,您的意见将不胜感激。
为了进一步确认,(也许是显而易见的)代码的输出只是每行的第 17 个值(产品类型)。我认为没有必要发布,因为我们在上面发布了输出的 1/4 值。
答: 暂无答案
下一个:反向括号
评论
row[17]
0