You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.0 KiB

import pandas as pd
import psycopg2 as psy
data = pd.read_csv(r'co2_emission.csv')
df = pd.DataFrame(data)
df2 = df.drop_duplicates()
co = None
try :
co = psy.connect(host='berlin',
database = 'dbmalanone',
user = 'malanone',
password = 'azertyuiop')
curs=co.cursor()
#Delete all the lines which has no data
curs.execute('''DELETE FROM CO_DEUX WHERE emission = 0''')
curs.execute('''DELETE FROM CO_DEUX WHERE code LIKE 'NaN' ''')
#Chart that picture the evolution of the emission in France
fig = df3.plot(x="annee", y="emissions", legend=False, style='-', kind='bar')
fig.set_title("Quantité d'émission (tonnes) en fonction des années")
fig.set_xlabel("Année")
fig.set_ylabel("Émissions")
fig.set_xticks(df3.index)
fig.set_xticklabels(df3['annee'], rotation='45')
fig.set_ylim(0,350)
plt.show()
co.commit()
except (Exception, psy.DatabaseError) as error :
print(error)
finally :
if co is not None:
co.close()