Skip to content

Commit

Permalink
Use regex to detect integer parseable string
Browse files Browse the repository at this point in the history
  • Loading branch information
Ru Chern Chong committed Jun 15, 2024
1 parent 4c3e452 commit e4b4e7c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion updater.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import csv
import datetime
import os
import re
import tempfile
import time
from typing import List, Dict, Any
Expand Down Expand Up @@ -38,8 +39,10 @@ async def updater(
row["make"] = row["make"].replace(".", "")
# Convert string values to numbers if possible
for key, value in row.items():
if isinstance(value, str):
if re.match(r"\b\d+(?:,\d+)?\b", value):
row[key] = 0 if value == "" else value
try:
value = str(int(value.replace(",", "")))
row[key] = float(value) if "." in value else int(value)
except ValueError:
pass
Expand Down

0 comments on commit e4b4e7c

Please sign in to comment.