Update app.py
Browse files
app.py
CHANGED
@@ -3,25 +3,25 @@ import pandas as pd
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
|
5 |
# Load data
|
6 |
-
|
7 |
-
|
8 |
|
9 |
|
10 |
# Sidebar - เลือกปีเริ่มต้นและสิ้นสุด
|
11 |
start_year = st.sidebar.selectbox("เลือกปีเริ่มต้น", options=list(range(2002, 2022)))
|
12 |
end_year= st.sidebar.selectbox("เลือกปีสิ้นสุด", options=list(range(start_year+1, 2024)))
|
13 |
|
14 |
-
|
15 |
-
|
16 |
# Filter data based on the year range
|
17 |
-
filtered_data =
|
18 |
-
filtered_data2 =
|
19 |
# Filter data based on selected years
|
20 |
|
21 |
|
22 |
# สร้างตัวเลือก Selectbox
|
23 |
selected_data = st.sidebar.selectbox("เลือกข้อมูลที่ต้องการโชว์",
|
24 |
-
options=["
|
25 |
|
26 |
# Filter data based on selected data type
|
27 |
|
@@ -32,14 +32,14 @@ filtered_data2 = filtered_data2[filtered_data2["symbol"] == selected_data]
|
|
32 |
st.write("### กราฟเส้น Time Series")
|
33 |
plt.figure(figsize=(10, 6))
|
34 |
for fuel_type, group_data in filtered_data.groupby("symbol"):
|
35 |
-
if fuel_type == "
|
36 |
-
plt.plot(group_data["
|
37 |
elif fuel_type == "LPG":
|
38 |
-
plt.plot(group_data["
|
39 |
-
elif fuel_type == "
|
40 |
-
plt.plot(group_data["
|
41 |
for fuel_type,group_data in filtered_data2.groupby("symbol"):
|
42 |
-
plt.plot(group_data["date"], group_data["
|
43 |
plt.xlabel("Date")
|
44 |
plt.ylabel("Value")
|
45 |
plt.title("Time Series")
|
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
|
5 |
# Load data
|
6 |
+
data_y = pd.read_csv("merged_y.csv")
|
7 |
+
data_p = pd.read_csv("merged_p.csv")
|
8 |
|
9 |
|
10 |
# Sidebar - เลือกปีเริ่มต้นและสิ้นสุด
|
11 |
start_year = st.sidebar.selectbox("เลือกปีเริ่มต้น", options=list(range(2002, 2022)))
|
12 |
end_year= st.sidebar.selectbox("เลือกปีสิ้นสุด", options=list(range(start_year+1, 2024)))
|
13 |
|
14 |
+
data_y['date'] = pd.to_datetime(data_y['date'])
|
15 |
+
data_p['date'] = pd.to_datetime(data_p['date'])
|
16 |
# Filter data based on the year range
|
17 |
+
filtered_data = data_y[(data_y["date"].dt.year >= start_year) & (data_y["date"].dt.year <= end_year)]
|
18 |
+
filtered_data2 = data_p[(data_p["date"].dt.year >= start_year) & (data_p["date"].dt.year <= end_year)]
|
19 |
# Filter data based on selected years
|
20 |
|
21 |
|
22 |
# สร้างตัวเลือก Selectbox
|
23 |
selected_data = st.sidebar.selectbox("เลือกข้อมูลที่ต้องการโชว์",
|
24 |
+
options=["Electricity", "LPG", "Diesel"])
|
25 |
|
26 |
# Filter data based on selected data type
|
27 |
|
|
|
32 |
st.write("### กราฟเส้น Time Series")
|
33 |
plt.figure(figsize=(10, 6))
|
34 |
for fuel_type, group_data in filtered_data.groupby("symbol"):
|
35 |
+
if fuel_type == "Electricity":
|
36 |
+
plt.plot(group_data["date"], group_data["Y"], label="Actual", color="yellow")
|
37 |
elif fuel_type == "LPG":
|
38 |
+
plt.plot(group_data["date"], group_data["Y"], label="Actual", color="green")
|
39 |
+
elif fuel_type == "Diesel":
|
40 |
+
plt.plot(group_data["date"], group_data["Y"], label="Actual", color="red")
|
41 |
for fuel_type,group_data in filtered_data2.groupby("symbol"):
|
42 |
+
plt.plot(group_data["date"], group_data["Y"], label="Predict",color="blue")
|
43 |
plt.xlabel("Date")
|
44 |
plt.ylabel("Value")
|
45 |
plt.title("Time Series")
|