File size: 2,566 Bytes
6d8eb1f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
import streamlit as st
import pandas as pd
import os
import matplotlib.pyplot as plt
import seaborn as sns
# Set the page config
st.set_page_config(page_title='Data Visualizer',
layout='wide',
page_icon='๐')
# Title
st.title('๐ Data Visualizer')
working_dir = os.path.dirname(os.path.abspath(__file__))
# Specify the folder where your CSV files are located
folder_path = f"{working_dir}/data" # Update this to your folder path
# List all files in the folder
files = [f for f in os.listdir(folder_path) if f.endswith('.csv')]
# Dropdown to select a file
selected_file = st.selectbox('Select a file', files, index=None)
if selected_file:
# Construct the full path to the file
file_path = os.path.join(folder_path, selected_file)
# Read the selected CSV file
df = pd.read_csv(file_path)
col1, col2 = st.columns(2)
columns = df.columns.tolist()
with col1:
st.write("")
st.write(df.head())
with col2:
# Allow the user to select columns for plotting
x_axis = st.selectbox('Select the X-axis', options=columns+["None"])
y_axis = st.selectbox('Select the Y-axis', options=columns+["None"])
plot_list = ['Line Plot', 'Bar Chart', 'Scatter Plot', 'Distribution Plot', 'Count Plot']
# Allow the user to select the type of plot
plot_type = st.selectbox('Select the type of plot', options=plot_list)
# Generate the plot based on user selection
if st.button('Generate Plot'):
fig, ax = plt.subplots(figsize=(6, 4))
if plot_type == 'Line Plot':
sns.lineplot(x=df[x_axis], y=df[y_axis], ax=ax)
elif plot_type == 'Bar Chart':
sns.barplot(x=df[x_axis], y=df[y_axis], ax=ax)
elif plot_type == 'Scatter Plot':
sns.scatterplot(x=df[x_axis], y=df[y_axis], ax=ax)
elif plot_type == 'Distribution Plot':
sns.histplot(df[x_axis], kde=True, ax=ax)
y_axis='Density'
elif plot_type == 'Count Plot':
sns.countplot(x=df[x_axis], ax=ax)
y_axis = 'Count'
# Adjust label sizes
ax.tick_params(axis='x', labelsize=10) # Adjust x-axis label size
ax.tick_params(axis='y', labelsize=10) # Adjust y-axis label size
# Adjust title and axis labels with a smaller font size
plt.title(f'{plot_type} of {y_axis} vs {x_axis}', fontsize=12)
plt.xlabel(x_axis, fontsize=10)
plt.ylabel(y_axis, fontsize=10)
# Show the results
st.pyplot(fig) |