|
import streamlit as st |
|
import pandas as pd |
|
import matplotlib.pyplot as plt |
|
|
|
|
|
data_y = pd.read_csv("merged_y.csv") |
|
data_p = pd.read_csv("merged_p.csv") |
|
|
|
|
|
|
|
start_year = st.sidebar.selectbox("เลือกปีเริ่มต้น", options=list(range(2002, 2022))) |
|
end_year= st.sidebar.selectbox("เลือกปีสิ้นสุด", options=list(range(start_year+1, 2024))) |
|
|
|
data_y['date'] = pd.to_datetime(data_y['date']) |
|
data_p['date'] = pd.to_datetime(data_p['date']) |
|
|
|
filtered_data = data_y[(data_y["date"].dt.year >= start_year) & (data_y["date"].dt.year <= end_year)] |
|
filtered_data2 = data_p[(data_p["date"].dt.year >= start_year) & (data_p["date"].dt.year <= end_year)] |
|
|
|
|
|
|
|
|
|
selected_data = st.sidebar.selectbox("เลือกข้อมูลที่ต้องการโชว์", |
|
options=["Electricity", "LPG", "Diesel"]) |
|
|
|
|
|
|
|
filtered_data = filtered_data[filtered_data["symbol"] == selected_data] |
|
filtered_data2 = filtered_data2[filtered_data2["symbol"] == selected_data] |
|
|
|
|
|
st.write("### กราฟเส้น Time Series") |
|
plt.figure(figsize=(10, 6)) |
|
for fuel_type, group_data in filtered_data.groupby("symbol"): |
|
if fuel_type == "Electricity": |
|
plt.plot(group_data["date"], group_data["Y"], label="Actual", color="yellow") |
|
elif fuel_type == "LPG": |
|
plt.plot(group_data["date"], group_data["Y"], label="Actual", color="green") |
|
elif fuel_type == "Diesel": |
|
plt.plot(group_data["date"], group_data["Y"], label="Actual", color="red") |
|
for fuel_type,group_data in filtered_data2.groupby("symbol"): |
|
plt.plot(group_data["date"], group_data["Y"], label="Predict",color="blue") |
|
plt.xlabel("Date") |
|
plt.ylabel("Value") |
|
plt.title("Time Series") |
|
plt.legend() |
|
st.pyplot(plt) |