Hint
🧠Not sure how to start building this file converter with Streamlit?
Here’s how you can break it down step by step:
Set up your app with Streamlit
import streamlit as st
st.title("CSV ↔ Excel Converter")
Add a file uploader that accepts both CSV and Excel:
uploaded_file = st.file_uploader("Upload a CSV or Excel file", type=["csv", "xlsx"])
Detect the file type based on the filename:
if uploaded_file.name.endswith(".csv"):
# Handle CSV
elif uploaded_file.name.endswith(".xlsx"):
# Handle Excel
Read the file with pandas:
For CSV:
pd.read_csv(uploaded_file)
For Excel:
pd.read_excel(uploaded_file)
Convert to the other format and create an in-memory file:
Use
BytesIO()
for Excel output.Use
.to_csv()
with.encode()
for CSV output.
Show the data with
st.dataframe(df)
And provide ast.download_button
so users can download the converted file.
✅ That’s all it takes!
Click Show Solution to see how to tie these steps together into a clean, functional Streamlit app.