Hint

🧠 Not sure how to start building this file converter with Streamlit?

Here’s how you can break it down step by step:

  1. Set up your app with Streamlit

import streamlit as st
st.title("CSV ↔ Excel Converter")
  1. Add a file uploader that accepts both CSV and Excel:

uploaded_file = st.file_uploader("Upload a CSV or Excel file", type=["csv", "xlsx"])
  1. Detect the file type based on the filename:

if uploaded_file.name.endswith(".csv"):
    # Handle CSV
elif uploaded_file.name.endswith(".xlsx"):
    # Handle Excel
  1. Read the file with pandas:

    • For CSV: pd.read_csv(uploaded_file)

    • For Excel: pd.read_excel(uploaded_file)

  2. Convert to the other format and create an in-memory file:

    • Use BytesIO() for Excel output.

    • Use .to_csv() with .encode() for CSV output.

  3. Show the data with st.dataframe(df)
    And provide a st.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.