DB-GPT/dbgpt/util/pd_utils.py
2024-02-28 16:47:29 +08:00

23 lines
629 B
Python

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):
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