SR05 commited on
Commit
80937eb
·
verified ·
1 Parent(s): e8f4f41

Update loading_file.py

Browse files
Files changed (1) hide show
  1. loading_file.py +14 -8
loading_file.py CHANGED
@@ -45,22 +45,28 @@ def fetch_data():
45
  # Process the .ods file
46
  ods_file = BytesIO(ods_response.content)
47
  df = pd.read_excel(ods_file, engine="odf")
48
- df.dropna(how="all", inplace=True)
 
 
 
 
 
49
  df.reset_index(drop=True, inplace=True)
50
 
51
- # Check columns and rename appropriately
52
- print("Columns before renaming:", df.columns.tolist()) # For debugging purposes
53
 
54
- # Attempt to rename columns only if there are sufficient columns
55
- if len(df.columns) >= 2:
 
 
 
 
56
  df.columns = ["Application Number", "Decision"]
57
  else:
58
  st.error("Insufficient data columns detected.")
59
  return None
60
 
61
- # Only keep relevant columns
62
- df = df[["Application Number", "Decision"]]
63
-
64
  df["Application Number"] = df["Application Number"].astype(str)
65
  return df
66
 
 
45
  # Process the .ods file
46
  ods_file = BytesIO(ods_response.content)
47
  df = pd.read_excel(ods_file, engine="odf")
48
+
49
+ # Print columns to inspect what they look like
50
+ print("Columns before cleaning:", df.columns.tolist()) # For debugging purposes
51
+
52
+ # Drop unnecessary columns
53
+ df.dropna(how="all", inplace=True) # Drop rows with all NaN values
54
  df.reset_index(drop=True, inplace=True)
55
 
56
+ # Print columns after cleaning
57
+ print("Columns after cleaning:", df.columns.tolist()) # For debugging purposes
58
 
59
+ # If we have extra columns, drop them
60
+ if len(df.columns) > 2:
61
+ df = df.iloc[:, :2] # Keep only the first two columns
62
+
63
+ # Rename columns if they match the expected ones
64
+ if len(df.columns) == 2:
65
  df.columns = ["Application Number", "Decision"]
66
  else:
67
  st.error("Insufficient data columns detected.")
68
  return None
69
 
 
 
 
70
  df["Application Number"] = df["Application Number"].astype(str)
71
  return df
72