Update dataframe.py (#8)
Browse files- Update dataframe.py (0ddcbc8b197e7eed005e7377ee4098f2e96b2a19)
- dataframe.py +10 -9
dataframe.py
CHANGED
@@ -1,27 +1,28 @@
|
|
1 |
import pandas as pd
|
2 |
import streamlit as st
|
3 |
|
4 |
-
def
|
5 |
try:
|
6 |
# Read the .ods file into a DataFrame
|
7 |
-
df = pd.read_excel(
|
8 |
|
9 |
-
# Clean
|
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
|
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 |
-
#
|
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
|
27 |
-
return
|
|
|
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
|