Create an app with the following: - Allows user to upload a CSV file - Gives users the following options to choose from: - Reorder the columns in file - Add a column to file - Download the final modified file
Drop files here
or click to upload
import streamlit as st
import pandas as pd
from io import StringIO
st.title("CSV File Editor")
# Upload file
uploaded_file = st.file_uploader("Upload your CSV file", type=['csv'])
if uploaded_file is not None:
# Read the CSV file
df = pd.read_csv(uploaded_file)
# Show original data
st.subheader("Original Data")
st.dataframe(df)
# Options
option = st.selectbox(
"Choose operation",
["Reorder columns", "Add new column"]
)
if option == "Reorder columns":
st.subheader("Reorder Columns")
column_order = st.multiselect(
"Drag to reorder columns",
df.columns.tolist(),
default=df.columns.tolist()
)
if len(column_order) == len(df.columns):
df = df[column_order]
else:
st.warning("Please select all columns")
elif option == "Add new column":
st.subheader("Add New Column")
new_column_name = st.text_input("Enter new column name")
new_column_value = st.text_input("Enter value for all rows")
if new_column_name and new_column_value:
df[new_column_name] = new_column_value
# Show modified data
st.subheader("Modified Data")
st.dataframe(df)
# Download button
csv = df.to_csv(index=False)
st.download_button(
label="Download modified CSV",
data=csv,
file_name="modified.csv",
mime="text/csv"
)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?