-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCO2_price.py
47 lines (40 loc) · 1.54 KB
/
CO2_price.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import math
import csv
import pandas as pd
from pandas_datareader import data
import matplotlib.pyplot as plt
#European Union Allowance Price
def average(list):
sum = 0
for val in list:
if not math.isnan(val):
sum+=val
return float(sum)/len(list)
# price: mean, minimum, q1, q3, maximum prices of each year
# create an opaqued graph with each indicator
df = pd.read_csv("carbon stuff workbook - European Credit Prices (1).csv")
indices = [i for i in range(0, df.shape[0])]
df = df.assign(index = indices)
df.set_index('index', inplace=True)
num_lines = df.shape[0]
print("Number of lines in the CSV file: ", num_lines)
# calculating the new indicators for the new csv -
needed_col = ['EUR_USD','NZ_USD', 'UK_USD', 'CHN_USD', 'WAS_USD']
years_list = [year for year in range(2005, 2024)]
dict= {'year':years_list,'EUR_USD':[],'NZ_USD':[], 'UK_USD':[], 'CHN_USD':[], 'WAS_USD':[]}
#every column
for c in range(0, len(needed_col)):
indicator = dict[needed_col[c]]
current_indx_yearlist = 0
#list of all price data (in this ETS) from this years_list[current_indx_yearlist] year
year_data = []
for i in range(0, df.shape[0]):
if df["Date"][i].find(str(years_list[current_indx_yearlist]))!= -1:
year_data.append(df[needed_col[c]][i])
else:
indicator.append(average(year_data))
current_indx_yearlist = current_indx_yearlist+1
year_data = []
indicator.append(sum(year_data)/len(year_data))
DF = pd.DataFrame(dict)
DF.to_csv('annual_mean_CO2_prices_by_ETS.csv')