Increase the accuracy of reading Excel (#1209)

This commit is contained in:
NuoweiWang
2024-02-28 16:47:29 +08:00
committed by GitHub
parent 08fcb4f744
commit 0837da48ba
2 changed files with 46 additions and 9 deletions

View File

@@ -1,6 +1,22 @@
import math
# def csv_colunm_foramt(val):
# if str(val).find("$") >= 0:
# return float(val.replace("$", "").replace(",", ""))
# if str(val).find("¥") >= 0:
# return float(val.replace("¥", "").replace(",", ""))
# return val
import pandas as pd
def csv_colunm_foramt(val):
if str(val).find("$") >= 0:
return float(val.replace("$", "").replace(",", ""))
if str(val).find("¥") >= 0:
return float(val.replace("¥", "").replace(",", ""))
return val
try:
if pd.isna(val):
return math.nan
if str(val).find("$") >= 0:
return float(val.replace("$", "").replace(",", ""))
if str(val).find("¥") >= 0:
return float(val.replace("¥", "").replace(",", ""))
return val
except ValueError:
return val