import pandas as pd
import numpy as np
import [Link] as plt
from sklearn.linear_model import LinearRegression
from datetime import datetime
# ---------------------------------------------------
# 1. LOAD THE DATA (adjust filename if needed)
# ---------------------------------------------------
# If your downloaded file is "Natural_Gas_Data.xls" or ".xlsx"
df = pd.read_excel("Natural Gas [Link]")
# Clean column names
[Link] = [[Link]().lower().replace(" ", "_") for c in [Link]]
# Rename if needed
if "date" not in [Link]:
[Link](columns={[Link][0]: "date"}, inplace=True)
if "price" not in [Link]:
[Link](columns={[Link][1]: "price"}, inplace=True)
# Convert date to datetime
df["date"] = pd.to_datetime(df["date"])
# Sort by date
df = df.sort_values("date")
# ---------------------------------------------------
# 2. VISUALIZE PRICE TREND
# ---------------------------------------------------
[Link](figsize=(10,5))
[Link](df["date"], df["price"])
[Link]("Natural Gas Prices Over Time")
[Link]("Date")
[Link]("Price")
[Link](True)
[Link]("price_trend.png") # stored as image
[Link]()
# ---------------------------------------------------
# 3. BUILD SIMPLE PREDICTION MODEL (Linear Regression)
# ---------------------------------------------------
# Convert dates to numeric for regression
df["time_index"] = (df["date"] - df["date"].min()).[Link]
X = df[["time_index"]]
y = df["price"]
model = LinearRegression()
[Link](X, y)
# ---------------------------------------------------
# 4. ESTIMATE PRICE FUNCTION
# ---------------------------------------------------
def estimate_price(input_date_str):
"""
Returns estimated gas price for a given date.
Example: estimate_price("2025-07-31")
"""
input_date = pd.to_datetime(input_date_str)
time_index = (input_date - df["date"].min()).days
pred = [Link]([[time_index]])[0]
return round(float(pred), 4)
# ---------------------------------------------------
# 5. EXTRAPOLATE ONE YEAR INTO THE FUTURE
# ---------------------------------------------------
last_date = df["date"].max()
future_dates = pd.date_range(start=last_date, periods=13, freq="M")
future_predictions = []
for d in future_dates:
future_predictions.append({
"date": d,
"predicted_price": estimate_price(str([Link]()))
})
future_df = [Link](future_predictions)
# Save prediction output file
future_df.to_csv("future_predictions.csv", index=False)
# ---------------------------------------------------
# Print sample
if __name__ == "__main__":
print("Last available date in data:", last_date.date())
print("Example estimate for 2025-07-31:", estimate_price("2025-07-31"))
print("Future predictions saved to future_predictions.csv")