본문 바로가기

분류 전체보기339

Streamlit 기본 문법(9) : 사이드바 & selectbox, tab 활용 ☘ 사이드바 활용 코드 예시 import matplotlib.pyplot as plt import streamlit as st import seaborn as sns def main(): st.title("확인") with st.sidebar: st.header("Sidebar") day = st.selectbox("요일 선택", ["Thur", "Fri", "Sat", "Sun"]) tips = sns.load_dataset("tips") filtered_tips = tips.loc[tips['day'] == day] #st.dataframe(filtered_tips) top_bill = filtered_tips['total_bill'].max() top_tip = filtered_tips['tip'].. 2023. 7. 28.
Streamlit 기본 문법(8) : 주식 데이터 조회 페이지 만들기(feat. 사이드바) 주식 데이터 조회 페이지 만들기 (with 사이드바) 1. 필요한 라이브러리 다운 import plotly.graph_objects as go import pandas as pd import streamlit as st import yfinance as yf import matplotlib.pyplot as plt 2. 사이드바에 주식 종목(티커)를 입력 / 시작 ~ 종료 날짜 생성 / 데이터 조회하는 코드 def main(): st.title("주식 데이터") st.sidebar.title("Stock Chart") ticker = st.sidebar.text_input("Enter a ticker (e. g. AAPL)", value = "AAPL") st.sidebar.markdown('Ticker.. 2023. 7. 28.
Streamlit 기본 문법(7) : MultiSelect(멀티셀렉트) 위젯 MultiSelect 사용하기 여러 개의 항목으로 multiSelect 위젯을 생성하는 코드 iris 데이터프레임에서 iris 의 유일값들을 선택, 멀티셀렉트 항목으로 지정 iris = sns.load_dataset('iris') cols = st.multiselect("복수의 컬럼 선택", iris.columns) #st.write(cols) filtered_iris = iris.loc[:, cols] st.dataframe(filtered_iris) 👉 결과 : 여러개의 항목을 선택할 수 있으며, 선택한 항목에 해당하는 데이터프레임 출력 2023. 7. 28.
Streamlit 기본 문법(6) : selectbox(셀렉트박스) 위젯 Select Box 사용하기 Selectbox의 요소(주제)에 따라 시각화 그래프를 보여주는 코드 iris = sns.load_dataset('iris') #select box 만들기 st.markdown("## Raw Data") st.dataframe(iris) st.markdown("", unsafe_allow_html=True) #html 코드 쓰고 싶을 때 st.markdown("### SelectBox") st.write(iris['species'].unique()) col_name = st.selectbox('1개의 종을 선택하세요!', iris['species'].unique()) st.write(col_name) #iris 종별로 result 값 나누기 result = iris.loc[i.. 2023. 7. 28.
Streamlit 기본 문법(5) : radio(라디오) 위젯 라디오 위젯 사용하기 3개의 라디오 버튼을 만들고, 서로 다른 유형의 그래프를 보여주는 코드 def plot_matplotlib(): st.title('산점도 Matplotlib') fig, ax = plt.subplots() ax.scatter(iris['sepal_length'], iris['sepal_width']) st.pyplot(fig) def plot_seaborn(): st.title('산점도 Seaborn') fig, ax = plt.subplots() sns.scatterplot(iris, x = 'sepal_length', y ='sepal_width') st.pyplot(fig) def plot_plotly(): st.title('Scatter Plot with Plotly') fi.. 2023. 7. 28.
Streamlit 기본 문법(4) : checkbox(체크박스) 위젯 체크박스 위젯 사용하기 체크박스를 클릭하면 시각화 그래프가 나타나는 코드 import streamlit as st import matplotlib.pyplot as plt import numpy as np # 체크박스 만들기 x = np.linspace(0, 10, 100) y = np.sin(x) show_plot = st.checkbox("시각화 보여주기") st.write(show_plot) fig, ax = plt.subplots() ax.plot(x, y) if show_plot: st.pyplot(fig) if __name__ == "__main__": main() 👉 결과 checkbox에 체크된 값이 ture 로 나타남 True/False 로 구분 2023. 7. 28.
Streamlit 기본 문법(3) : slider, button 위젯 활용하기 1. 위젯 사용해서 매출 계산하기 1 - 1. 위젯 함수 정의 1. 매출액 계산하는 함수 정의 2. 슬라이더 위젯 활용 : price 슬라이더와 total_sales 슬라이더 만들기 3. 버튼 위젯 활용 : result 에 매출액 계산 함수 지정하여 출력 1 - 2. 결과 2023. 7. 28.
Streamlit 기본 문법(2) : 데이터프레임 시각화 데이터프레임 시각화 1. 필요한 라이브러리 import # -*- coding:utf-8 -*- import streamlit as st import pandas as pd import seaborn as sns import matplotlib.pyplot as plt import plotly.graph_objects as go from plotly.subplots import make_subplots 2. 함수 작성 : 데이터프레임 불러오기, 요약 metrix 보여주기 def main(): ## 데이터 프레임 st.title('데이터 프레임') df = sns.load_dataset('iris') st.dataframe(df.head(50)) #옵션이 다양함, documents 참고 st.write(d.. 2023. 7. 28.
Streamlit 기본 문법(1) Streamlit 시작하기 1. 함수 정의 & 실행 문법 작성 # -*- coding:utf-8 -*- import streamlit as st def main(): st.title("Hello World!") #실행 문법 if __name__ == "__main__": main() 2. Streamlit 시작하는 터미널 명령어 streamlit run app.py 실습해보기 예제 1. input 영역 생성 [코드] [결과] 예제 2. 마크다운으로 한 줄 씩 쓰기 [코드] [결과] 예제 3. 마크다운으로 여러 줄 쓰기 [코드] [결과] 예제 4. HTML CSS 스타일 적용하기 [코드] st.title('HTML CSS 마크다운 적용') html_css = """ 이름 나이 직업 Evan 25 데이터 .. 2023. 7. 28.
728x90