<jupyter_start><jupyter_text><jupyter_code>!unzip /content/archive.zip
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
!ls
power_gen= pd.read_csv("/content/file_02.csv")
power_gen.head(2)
power_gen.columns<jupyter_output><empty_output><jupyter_text>Checking the shape of the dataset that is, the number of rows and columns<jupyter_code>power_gen.shape<jupyter_output><empty_output><jupyter_text>Checking the data type of the columns for our analysis<jupyter_code>power_gen.dtypes<jupyter_output><empty_output><jupyter_text>Here we can see that the columns are not evenly categorized in the same data types so we will convert them to a uniform data format that is in integer or float format and will also convert the date column to date time format to carry out the predictive analysis part.<jupyter_code>power_gen["Thermal Generation Actual (in MU)"]= power_gen["Thermal Generation Actual (in MU)"].str.replace(',','').astype('float')
power_gen['Thermal Generation Estimated (in MU)']= power_gen['Thermal Generation Estimated (in MU)'].str.replace(',','').astype('float')
power_gen["Date"]= pd.to_datetime(power_gen["Date"])
power_gen.dtypes<jupyter_output><empty_output><jupyter_text>Checking for NAN values in the dataset<jupyter_code>power_gen.isna().sum()<jupyter_output><empty_output><jupyter_text>Here NAN values basically means that there is no nuclear power genration in the regions therefore we will be replacing these NAN vaues with 0.<jupyter_code>power_gen.fillna(0, axis=0, inplace=True)
power_gen.isna().sum()<jupyter_output><empty_output><jupyter_text>Using groupby to aggregate the total energy generated in different regions<jupyter_code>x=power_gen.groupby(by=['Region'],as_index=False).sum()
x
x.dtypes<jupyter_output><empty_output><jupyter_text>Data Visualizations Thermal Plots Actual and Estimated<jupyter_code>plt.figure(figsize=(10,10))

sns.relplot(x=power_gen.Region, y= power_gen["Thermal Generation Actual (in MU)"], kind="line", color="red")
sns.relplot(x=power_gen.Region, y= power_gen["Thermal Generation Estimated (in MU)"], kind="line", color="green")

plt.show()<jupyter_output><empty_output><jupyter_text>Above we can see that the estimated and actual power generation is similar. Nuclear Plots Actual and Estimated<jupyter_code>plt.figure(figsize=(15,10))

power_gen.plot(x='Date',y=['Nuclear Generation Actual (in MU)', 'Nuclear Generation Estimated (in MU)'], kind="line")

plt.show()<jupyter_output><empty_output><jupyter_text>Above we can see that the estimated power generation is lagging exactness with the actual one and therefore the actual power generated is much higher than estimation  Hydro Plots Actual and Estimated<jupyter_code>plt.figure(figsize=(15,10))

power_gen.plot(x='Date',y=['Hydro Generation Actual (in MU)', 'Hydro Generation Estimated (in MU)'])

plt.show()<jupyter_output><empty_output><jupyter_text>Hydro plots actual and estimated looks nearly the same Actual Nuclear Power Generation in Different Regions<jupyter_code>fig, ax = plt.subplots(figsize=(8,10))
power_gen.groupby(['Date','Region']).sum()['Nuclear Generation Actual (in MU)'].unstack().plot(ax=ax)
ax.set_xlabel('Date')
ax.set_ylabel('Nuclear Generation in different regions')<jupyter_output><empty_output><jupyter_text>Here we can see that Southern region has higher nuclear power generated compared to other regions Actual Thermal Power Generation in Different Regions<jupyter_code>fig, ax = plt.subplots(figsize=(8,10))
power_gen.groupby(['Date','Region']).sum()['Thermal Generation Actual (in MU)'].unstack().plot(ax=ax)
ax.set_xlabel('Date')
ax.set_ylabel('Thermal Generation in different regions')<jupyter_output><empty_output><jupyter_text>Here we can see that Western region dominates in terms of thermal power generation Actual Hydro Power Generation in Different Regions<jupyter_code>fig, ax = plt.subplots(figsize=(8,10))
power_gen.groupby(['Date','Region']).sum()['Hydro Generation Actual (in MU)'].unstack().plot(ax=ax)
ax.set_xlabel('Date')
ax.set_ylabel('Hydro Generation in different regions')<jupyter_output><empty_output><jupyter_text>Here Northern region dominates in terms of hydro power generation Plotting a Pie Plot to see the distribution of all the three energies in the nation<jupyter_code>df = [power_gen['Thermal Generation Estimated (in MU)'].sum(),power_gen['Nuclear Generation Estimated (in MU)'].sum(),power_gen['Hydro Generation Estimated (in MU)'].sum()]
labels = 'THERMAL%','NUCLEAR%','HYDRO%'
plt.pie(df, labels=labels, autopct='%1.1f%%', startangle=25)
plt.title('Power Generated From All the Three Sources')
plt.axis('equal')
plt.show()<jupyter_output><empty_output><jupyter_text>Above we can see that Thermal is the most dominated power generator compared to to other 2 followed by Hydro and then Nuclear Loading the state wise dataset containing the area and national share details<jupyter_code>state_wise= pd.read_csv("/content/State_Region_corrected.csv")
state_wise.head()<jupyter_output><empty_output><jupyter_text>Grouping the state data as per the regions to get an idea about the area and national share<jupyter_code>share = state_wise.groupby('Region').agg('sum')
share = share.reset_index()
share<jupyter_output><empty_output><jupyter_text>Plotting the National Share of Power State Wise<jupyter_code>plt.figure(figsize=(10,10))

ax = sns.barplot(x="State / Union territory (UT)", y= "National Share (%)", data= state_wise)


ax.set_xticklabels(ax.get_xticklabels(), rotation=40, ha="right")
plt.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>Above we can see that Rajasthan has the most number of National Share in terms of Power followed by MP, Maharashtra, UP. The least share is contained with Delhi, Chandigarh, Dadra and Nagar Haveli and Daman and Diu. Forecasting Future Values of 365 days for Thermal Power<jupyter_code>from fbprophet import Prophet
prophet = power_gen[['Date','Thermal Generation Actual (in MU)']]
prophet.columns= ["ds", "y"]
prophet.head(5)
prophet.dtypes
model= Prophet()
model.fit(prophet)
future = model.make_future_dataframe(periods = 365)
forecast = model.predict(future)
forecast
forecast[["ds","yhat","yhat_lower","yhat_upper"]].head()
fore= forecast[["ds","yhat","yhat_lower","yhat_upper"]]
fore.to_csv("forecasted_energy.csv")<jupyter_output><empty_output><jupyter_text>Graphical representation of the predicted output<jupyter_code>ther= model.plot(forecast, xlabel = 'Date', ylabel = 'Thermal Power generation')
plot= model.plot_components(forecast)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11717689639571709, 'fraction_numerical': 0.006786306741064696, 'mean_word_length': 7.890080428954423, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '19', 'dir': 'jupyter-structured-clean-dedup', 'id': '403289', 'license': 'Apache-2.0', 'n_tokens_mistral': 2234, 'n_tokens_neox': 2128, 'n_words': 577, 'path': 'Research_Energy_Consumption_India.ipynb', 'repo_name': 'Sagu12/EnergyManagementResearch', 'size': '6631'}