SR05's picture
Create dataframe.py
aa0cd67 verified
raw
history blame
1.05 kB
import pandas as pd
import streamlit as st
def process_dataframe(ods_file):
try:
# Read the .ods file into a DataFrame
df = pd.read_excel(ods_file, engine='odf')
# Clean up unnecessary columns and rows
df.drop(columns=["Unnamed: 0", "Unnamed: 1"], inplace=True, errors='ignore')
df.dropna(how='all', inplace=True)
df.reset_index(drop=True, inplace=True)
# Identify and set the header row
for idx, row in df.iterrows():
if row['Unnamed: 2'] == 'Application Number' and row['Unnamed: 3'] == 'Decision':
df.columns = ['Application Number', 'Decision']
df = df.iloc[idx + 1:]
break
# Convert application numbers to strings
df.reset_index(drop=True, inplace=True)
df['Application Number'] = df['Application Number'].astype(str)
return df
except Exception as e:
st.error(f"Error processing the data: {e}")
return pd.DataFrame() # Return an empty DataFrame on failure