|
import streamlit as st |
|
import pandas as pd |
|
import matplotlib.pyplot as plt |
|
|
|
|
|
data = pd.read_csv("Graph_hugging_Y.csv") |
|
data2 = pd.read_csv("Graph_hugging_predict.csv") |
|
|
|
|
|
|
|
start_year = st.sidebar.selectbox("เลือกปีเริ่มต้น", options=list(range(2002, 2022))) |
|
end_year= st.sidebar.selectbox("เลือกปีสิ้นสุด", options=list(range(start_year+1, 2024))) |
|
|
|
data['date_Y'] = pd.to_datetime(data['date_Y']) |
|
data2['date'] = pd.to_datetime(data2['date']) |
|
|
|
filtered_data = data[(data["date_Y"].dt.year >= start_year) & (data["date_Y"].dt.year <= end_year)] |
|
filtered_data2 = data2[(data2["date"].dt.year >= start_year) & (data2["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_Y"], group_data["Y"], label="Actual", color="yellow") |
|
elif fuel_type == "LPG": |
|
plt.plot(group_data["date_Y"], group_data["Y"], label="Actual", color="green") |
|
elif fuel_type == "DIESEL": |
|
plt.plot(group_data["date_Y"], group_data["Y"], label="Actual", color="red") |
|
for fuel_type,group_data in filtered_data2.groupby("symbol"): |
|
plt.plot(group_data["date"], group_data["predict"], label="Predict",color="blue") |
|
plt.xlabel("Date") |
|
plt.ylabel("Value") |
|
plt.title("Time Series") |
|
plt.legend() |
|
st.pyplot(plt) |