Create dataframe.py
Browse files- dataframe.py +27 -0
dataframe.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|