import streamlit as st
import pandas as pd
import plotly.express as px
# 页面标题
st.title('数据可视化应用')
# 数据上传
uploaded_file = st.file_uploader('上传数据集(支持CSV和Excel格式)', type=['csv', 'xlsx'])
if uploaded_file is not None:
# 根据文件类型读取数据
if uploaded_file.name.endswith('.csv'):
data = pd.read_csv(uploaded_file)
elif uploaded_file.name.endswith(('.xls', '.xlsx')):
data = pd.read_excel(uploaded_file)
# 显示数据摘要信息
st.subheader('数据摘要')
st.write(data.head())
# 数据探索
st.subheader('数据探索')
# 列选择框
selected_column = st.selectbox('选择一个要探索的列', data.columns)
# 数据类型判断
column_type = data[selected_column].dtype
if column_type == 'object':
# 非数值型数据