Postcodes / ingest.py
Alealejandrooo's picture
Update ingest.py
af22e18 verified
raw
history blame contribute delete
566 Bytes
import pandas as pd
import gradio as gr
def load_data(filepath):
# Check the file extension and load the file accordingly
if filepath.endswith('.csv'):
df = pd.read_csv(filepath)
elif filepath.endswith('.xlsx') or filepath.endswith('.xls'):
df = pd.read_excel(filepath)
else:
raise gr.Error("Unsupported file format: Please provide a .csv or .xlsx file")
# Convert all string values to lowercase and remove spaces
df = df.map(lambda x: x.lower().replace(" ", "") if isinstance(x, str) else x)
return df