Fixed exception (nan).

parent b85791a0
...@@ -43,15 +43,29 @@ def numeric_conversion(datafile): ...@@ -43,15 +43,29 @@ def numeric_conversion(datafile):
verify_num_col = [x for x in datafile.columns if x in numeric_variables] verify_num_col = [x for x in datafile.columns if x in numeric_variables]
for col in verify_num_col: for col in verify_num_col:
newdata = []
for x in datafile[col]:
try:
newdata.append(float(x))
except:
newdata.append(None)
datafile[col] = [float(x) if str(x) =="nan" else None for x in datafile[col]] datafile[col] = newdata
#datafile[col] = [float(x) if str(x) !="nan" else None for x in datafile[col]]
verify_cat_col = [x for x in datafile.columns if x in categorical_variables] verify_cat_col = [x for x in datafile.columns if x in categorical_variables]
for col in verify_cat_col: for col in verify_cat_col:
newdata = []
datafile[col] = [str(x) if str(x) =="nan" else None for x in datafile[col]] for x in datafile[col]:
try:
newdata.append(str(x))
except:
newdata.append(None)
datafile[col] = newdata
#datafile[col] = [str(x) if str(x) !="nan" else None for x in datafile[col]]
#new_datafile_path = datafile_path.replace(".csv", "_numeric.csv") #new_datafile_path = datafile_path.replace(".csv", "_numeric.csv")
#datafile.to_csv(new_datafile_path, index = False, quoting=csv.QUOTE_NONNUMERIC) #datafile.to_csv(new_datafile_path, index = False, quoting=csv.QUOTE_NONNUMERIC)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment