我需要檢查 csv 檔案上的第一個值。它需要匹配特定的字串。“ddd.dddd”所有數字。所有 CSV 值都以“”開頭和結尾
來自 CSV 的示例字串
"123.12345"
到目前為止的代碼是
import re
import csv
strformat = re.compile('\"\d{3}\.\d{5}\"')
with open(final_file, newline='') as fin:
for f in csv.reader(fin[0]):
if strformat is not None:
print ("Match")
else:
print ("No Match")
uj5u.com熱心網友回復:
你需要像這樣反轉你的代碼,
# The expression is changed
strformat = re.compile(r'\d{3}\.\d{5}')
with open(final_file, newline='') as fin:
for row in csv.reader(fin):
# You have to check match like this
if strformat.match(row[0]):
print ("Match")
else:
print ("No Match")
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/515569.html
上一篇:pyspark中的Regexp_Replace無法正常作業
下一篇:用pandas從csv實體化
