๐ก ๋ณธ ํฌ์คํ
์ ์์
๋ด์ฉ, ๊ต์ฌ, ChatGPT๋ฅผ ์ฐธ๊ณ ํ์ฌ ์ ๋ฆฌํ ํ์ต ๊ธฐ๋ก์
๋๋ค.
๊ธ๊ณผ ๊ทธ๋ฆผ ๋ฑ ๋ชจ๋ ์ฝํ
์ธ ์ ์ ๋ฆฌ ๋ฐ ์์ฑ์ ๋ณธ ๋ธ๋ก๊ทธ์์ ์ง์ ์ ์๋์์ต๋๋ค.
Python ๊ธฐ์ด๋ถํฐ Streamlit ๋ฐ์ดํฐ ์๊ฐํ๊น์ง ์ ๋ฆฌํ๋ ํ์ต ๊ธฐ๋ก์ ๋๋ค.
์ด ๊ธ์ '21. [Streamlit] ๋ฐ์ดํฐ ์๊ฐํ์ ์ฌ์ฉ์ ์ ๋ ฅ' ์ ๋๋ค.
๋ฐ์ดํฐ ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ๊ณต์ ํ ๋ ๋จ์ํ ํ๋ณด๋ค ์๊ฐํ๋ ๊ทธ๋ํ๊ฐ ํจ์ฌ ์ดํดํ๊ธฐ ์ฝ๋ค.
Streamlit์ Python ์ฝ๋๋ง์ผ๋ก ๋ฐ์ดํฐ ์๊ฐํ์ ์ฌ์ฉ์ ์ธํฐํ์ด์ค(UI) ๋ฅผ ์ฝ๊ฒ ๋ง๋ค ์ ์๋ ๋๊ตฌ์ด๋ค.
์ด๋ฒ ๊ธ์์๋ Streamlit์ ํ์ฉํ์ฌ
- ๋ฐ์ดํฐ ์๊ฐํ
- ์ฌ์ฉ์ ์ ๋ ฅ ์ธํฐํ์ด์ค
- ๋์ ์ผ๋ก ๋ฐ๋๋ ๊ทธ๋ํ
๋ฅผ ๋ง๋๋ ๋ฐฉ๋ฒ์ ์ ๋ฆฌํด๋ณธ๋ค.
๐ก streamlit ์ค์น ํ, pandas, numpy, matplotlib๋ ์ค์นํด์ฃผ์.
๋งฅ๋ถ์ ๊ฒฝ์ฐ, pip ๋๋ python ์ ์ฌ์ฉํ ๋ pip3, pyhon3 ๋ก ์์ฑํด์ฃผ๋ฉด ๋๋ค.
pip3 install pandas numpy matplotlib
๋ฐ์ดํฐ ์๊ฐํ ๊ธฐ๋ณธ
Streamlit์์๋ DataFrame์ ์ด์ฉํด ๊ฐ๋จํ๊ฒ ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆด ์ ์๋ค.
๋จผ์ ์์ ๋ฐ์ดํฐ๋ฅผ ๋ง๋ค์ด๋ณด์.
import streamlit as st
import pandas as pd
import numpy as np
st.title("Monthly Sales Dashboard")
months = pd.date_range("2024-01-01", periods=12, freq="ME")
sales = np.random.randint(20000, 50000, size=12)
df = pd.DataFrame({
"Month": months.strftime("%Y-%m"),
"Sales": sales
})
๋ฐ์ดํฐ๋ฅผ ํ์ธํด๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ๋ค.
st.dataframe(df)
์ด์ ๊ทธ๋ํ๋ฅผ ๊ทธ๋ ค๋ณด์.
๋ผ์ธ ์ฐจํธ
Streamlit์์๋ st.line_chart()๋ก ๊ฐ๋จํ๊ฒ ์ ๊ทธ๋ํ๋ฅผ ๋ง๋ค ์ ์๋ค.
st.subheader("Monthly Sales Trend")
st.line_chart(df.set_index("Month"))
์ด ๊ทธ๋ํ๋ ์๋ณ ๋งค์ถ ํ๋ฆ์ ํ๋์ ๋ณด์ฌ์ค๋ค.
๋ฐ ์ฐจํธ
๋ง๋ ๊ทธ๋ํ๋ ๋น๊ต๋ฅผ ์๊ฐ์ ์ผ๋ก ๋ณด์ฌ์ค ๋ ์ ์ฉํ๋ค.
st.subheader("Monthly Sales Comparison")
st.bar_chart(df.set_index("Month"))
์ด ๊ทธ๋ํ๋ฅผ ํตํด ์๋ณ ๋งค์ถ ๊ท๋ชจ ์ฐจ์ด๋ฅผ ์ฝ๊ฒ ํ์ธํ ์ ์๋ค.
์ฌ์ฉ์ ์
๋ ฅ ์ถ๊ฐ
Streamlit์ ๊ฐ๋ ฅํ ๊ธฐ๋ฅ ์ค ํ๋๋ ์ฌ์ฉ์ ์ ๋ ฅ์ ์ฝ๊ฒ ๋ฐ์ ์ ์๋ค๋ ์ ์ด๋ค.
์๋ฅผ ๋ค์ด ๋ฐ์ดํฐ ๊ฐ์๋ฅผ ์กฐ์ ํ๋ ์ฌ๋ผ์ด๋๋ฅผ ๋ง๋ค์ด๋ณด์.
num_data = st.slider("Number of Data Points", 5, 50, 20)
๋๋ค ๋ฐ์ดํฐ๋ฅผ ์์ฑํด ๊ทธ๋ํ๋ฅผ ๊ทธ๋ ค๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ๋ค.
data = np.random.randn(num_data)
chart_data = pd.DataFrame({
"value": data
})
st.line_chart(chart_data)
์ฌ๋ผ์ด๋๋ฅผ ์์ง์ด๋ฉด ๊ทธ๋ํ๊ฐ ์ค์๊ฐ์ผ๋ก ๋ฐ๋๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.

์ธํฐ๋ํฐ๋ธ ์๊ฐํ ์์
์ด๋ฒ์๋ ์กฐ๊ธ ๋ ์ฌ๋ฏธ์๋ ์์ ๋ฅผ ๋ง๋ค์ด๋ณด์.
๋๋ค ๋ฐ์ดํฐ๋ก ์์ฑ๋๋ "๋ฐ์ดํฐ ์คํธ๋ฆผ ๊ทธ๋ํ"์ด๋ค.
import streamlit as st
import pandas as pd
import numpy as np
st.subheader("Real-time Style Random Data")
points = st.slider("Number of Points", 10, 200, 50)
data = np.cumsum(np.random.randn(points))
df_random = pd.DataFrame({
"value": data
})
st.line_chart(df_random)

์ด ๊ทธ๋ํ๋ ๋๋คํ๊ฒ ๋ณํํ๋ ๋ฐ์ดํฐ ํ๋ฆ์ ๋ณด์ฌ์ค๋ค.
๊ฐ๋จํ ๋ฐ์ดํฐ ๋ถ์ ๋์๋ณด๋
์ด๋ฒ์๋ ์์ ์๊ฐ์ ๋ค๋ฃฌ Python ํจ์๋ค์ ํ์ฉํด
๊ฐ๋จํ ๋ฐ์ดํฐ ๋ถ์ ๋์๋ณด๋๋ฅผ ๋ง๋ค์ด๋ณด์.
import streamlit as st
import pandas as pd
import numpy as np
scores = np.random.randint(60, 100, 20)
df_scores = pd.DataFrame({
"score": scores
})
st.subheader("Score Distribution")
st.bar_chart(df_scores)
# ์ด ๋ฐ์ดํฐ์ ๋ํด ๊ธฐ๋ณธ ํต๊ณ๋ฅผ ๊ณ์ฐํด๋ณผ ์๋ ์๋ค.
st.write("Average Score:", np.mean(scores))
st.write("Max Score:", np.max(scores))
st.write("Min Score:", np.min(scores))

์ด์ฒ๋ผ Python์์ ๋ฐฐ์ด
- mean
- max
- min
๊ฐ์ ๊ณ์ฐ์ ๊ทธ๋๋ก ์น ์ธํฐํ์ด์ค์์ ์๊ฐ์ ์ผ๋ก ํํํ ์ ์๋ค.
Matplotlib ํ์ฉ
Streamlit์์๋ matplotlib ๊ทธ๋ํ๋ ์ฌ์ฉํ ์ ์๋ค.
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
# ๋ฐ์ดํฐ ์์ฑ
df = pd.DataFrame({
"Month": ["Jan", "Feb", "Mar", "Apr"],
"Sales": [20000, 25000, 30000, 28000]
})
fig, ax = plt.subplots()
ax.plot(df["Month"], df["Sales"], marker="o")
ax.set_title("Monthly Sales Example")
ax.set_xlabel("Month")
ax.set_ylabel("Sales")
plt.xticks(rotation=45)
st.pyplot(fig)

์ด ๋ฐฉ์์ ๊ทธ๋ํ๋ฅผ ์ธ๋ฐํ๊ฒ ์ปค์คํฐ๋ง์ด์งํ ๋ ์ ์ฉํ๋ค.
Streamlit ์๊ฐํ์ ์ฅ์
Streamlit์ ํ์ฉํ ๋ฐ์ดํฐ ์๊ฐํ์ ์ฅ์ ์ ๋ค์๊ณผ ๊ฐ๋ค.
- Python ์ฝ๋๋ง์ผ๋ก ์น ๋์๋ณด๋ ์์ฑ
- ์ฌ์ฉ์ ์ ๋ ฅ ๊ธฐ๋ฐ ์ธํฐ๋ํฐ๋ธ ๊ทธ๋ํ
- ๋น ๋ฅธ ํ๋กํ ํ์ดํ
- ๋ฐ์ดํฐ ๋ถ์ ๊ฒฐ๊ณผ ๊ณต์ ์ ์ ํฉ
ํนํ ๋ฐ์ดํฐ ๋ถ์์ด๋ ๋ฐ์ดํฐ ์์ง๋์ด๋ง ํ๊ฒฝ์์ ๊ฐ๋จํ ๋์๋ณด๋๋ ์คํ์ฉ ๋ฐ์ดํฐ ์๊ฐํ ๋๊ตฌ๋ก ๋ง์ด ์ฌ์ฉ๋๋ค.
์ ๋ฆฌ
Streamlit์ ์ฌ์ฉํ๋ฉด Python ์ฝ๋๋ง์ผ๋ก๋ ๋ฐ์ดํฐ ์๊ฐํ์ ์ฌ์ฉ์ ์ธํฐํ์ด์ค๋ฅผ ์ฝ๊ฒ ๋ง๋ค ์ ์๋ค.
์ด๋ฒ ๊ธ์์๋
- st.line_chart()
- st.bar_chart()
- st.slider()
- st.pyplot()
๋ฑ์ ํ์ฉํ์ฌ ๋ฐ์ดํฐ ์๊ฐํ์ ์ฌ์ฉ์ ์ ๋ ฅ ๊ธฐ๋ฅ์ ๊ตฌํํด๋ณด์๋ค.
์ด๋ฌํ ๊ธฐ๋ฅ์ ํ์ฉํ๋ฉด ๋ฐ์ดํฐ ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ํจ์ฌ ์ง๊ด์ ์ผ๋ก ์ ๋ฌํ ์ ์๋ ์น ์ฑ์ ๋ง๋ค ์ ์๋ค.
Python๊ณผ ๋ฐ์ดํฐ ๋ถ์์ ๊ณต๋ถํ๋ ๊ณผ์ ์์ Streamlit์ ๋ฐ์ดํฐ ๊ฒฐ๊ณผ๋ฅผ ์๊ฐ์ ์ผ๋ก ๋ณด์ฌ์ฃผ๋ ๋งค์ฐ ์ ์ฉํ ๋๊ตฌ๊ฐ ๋๋ค.
'Python & SQL > Python Basics' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| 20. [Streamlit] ์ค์น๋ถํฐ ์ฒซ ํ๋ฉด๊น์ง (0) | 2026.03.08 |
|---|---|
| 19. [ํ์ด์ฌ] ์ ๋ ฌ ๊ธฐ์ ๊ณผ ์ ์ฉํ ์ ํธ ํจ์ (0) | 2026.03.08 |
| 18. [ํ์ด์ฌ] ๋ชจ๋๊ณผ ํ๋ก์ ํธ ๊ตฌ์กฐ (2) | 2026.03.08 |
| 17. [ํ์ด์ฌ] ํด๋ก์ ์ ๋ฐ์ฝ๋ ์ดํฐ (2) | 2026.03.08 |
| 16. [ํ์ด์ฌ] class methos vs static method (2) | 2026.03.08 |