import streamlit as st import pandas as pd import matplotlib.pyplot as plt import seaborn as sns # Function to plot a bar chart def plot_bar_chart(df): plt.figure(figsize=(8, 6)) sns.barplot(x='Category', y='Value', data=df) plt.title('Category vs Value') plt.xlabel('Category') plt.ylabel('Value') plt.tight_layout() return plt # Function to plot a line chart def plot_line_chart(df): plt.figure(figsize=(8, 6)) sns.lineplot(x='Category', y='Value', data=df) plt.title('Category vs Value') plt.xlabel('Category') plt.ylabel('Value') plt.tight_layout() return plt # Function to plot a pie chart def plot_pie_chart(df): plt.figure(figsize=(8, 6)) df.set_index('Category')['Value'].plot.pie(autopct='%1.1f%%', figsize=(8, 6)) plt.title('Category Distribution') return plt # Streamlit interface st.title('Advanced Data Visualization App') # Upload CSV file uploaded_file = st.file_uploader("Upload your CSV file", type=["csv"]) if uploaded_file is not None: # Load CSV into a pandas DataFrame df = pd.read_csv(uploaded_file) # Display the dataframe st.write(df) # Chart type selection chart_type = st.selectbox('Select the chart type:', ['Bar Chart', 'Line Chart', 'Pie Chart']) # Plot based on selected chart type if chart_type == 'Bar Chart': st.pyplot(plot_bar_chart(df)) elif chart_type == 'Line Chart': st.pyplot(plot_line_chart(df)) elif chart_type == 'Pie Chart': st.pyplot(plot_pie_chart(df))