SR05 commited on
Commit
62f4c5f
·
verified ·
1 Parent(s): 82e2987

Update dataframe.py (#8)

Browse files

- Update dataframe.py (0ddcbc8b197e7eed005e7377ee4098f2e96b2a19)

Files changed (1) hide show
  1. dataframe.py +10 -9
dataframe.py CHANGED
@@ -1,27 +1,28 @@
1
  import pandas as pd
2
  import streamlit as st
3
 
4
- def process_dataframe(ods_file):
5
  try:
6
  # Read the .ods file into a DataFrame
7
- df = pd.read_excel(ods_file, engine='odf')
8
 
9
- # Clean up unnecessary columns and rows
10
  df.drop(columns=["Unnamed: 0", "Unnamed: 1"], inplace=True, errors='ignore')
11
  df.dropna(how='all', inplace=True)
12
  df.reset_index(drop=True, inplace=True)
13
 
14
- # Identify and set the header row
15
  for idx, row in df.iterrows():
16
  if row['Unnamed: 2'] == 'Application Number' and row['Unnamed: 3'] == 'Decision':
17
  df.columns = ['Application Number', 'Decision']
18
- df = df.iloc[idx + 1:]
19
  break
20
 
21
- # Convert application numbers to strings
22
  df.reset_index(drop=True, inplace=True)
23
- df['Application Number'] = df['Application Number'].astype(str)
 
24
  return df
25
  except Exception as e:
26
- st.error(f"Error processing the data: {e}")
27
- return pd.DataFrame() # Return an empty DataFrame on failure
 
1
  import pandas as pd
2
  import streamlit as st
3
 
4
+ def prepare_dataframe(file):
5
  try:
6
  # Read the .ods file into a DataFrame
7
+ df = pd.read_excel(file, engine='odf')
8
 
9
+ # Clean the DataFrame
10
  df.drop(columns=["Unnamed: 0", "Unnamed: 1"], inplace=True, errors='ignore')
11
  df.dropna(how='all', inplace=True)
12
  df.reset_index(drop=True, inplace=True)
13
 
14
+ # Identify the header row and reformat the DataFrame
15
  for idx, row in df.iterrows():
16
  if row['Unnamed: 2'] == 'Application Number' and row['Unnamed: 3'] == 'Decision':
17
  df.columns = ['Application Number', 'Decision']
18
+ df = df.iloc[idx + 1:] # Skip the header row
19
  break
20
 
21
+ # Reset the index and convert the Application Number to integers
22
  df.reset_index(drop=True, inplace=True)
23
+ df['Application Number'] = df['Application Number'].astype(str).str.strip()
24
+
25
  return df
26
  except Exception as e:
27
+ st.error(f"Error preparing the DataFrame: {e}")
28
+ return None