diff --git a/script2.py b/script2.py index 3e06a2d..0ed6c0b 100644 --- a/script2.py +++ b/script2.py @@ -1,7 +1,7 @@ import pandas as pd import psycopg2 as psy import matplotlib.pyplot as plt - +import seaborn as sns data = pd.read_csv(r'co2_emission.csv') df = pd.DataFrame(data) @@ -21,7 +21,7 @@ try : curs.execute('''DELETE FROM CO_DEUX WHERE code LIKE 'NaN' ''') #Chart that picture the evolution of the emission in France - df3 = pd.read_sql('''SELECT * FROM CO_DEUX WHERE code LIKE 'FRA' AND year BETWEEN 1980 AND 2017;''',con=co) + df3 = pd.read_sql('''SELECT * FROM CO_DEUX WHERE code LIKE 'FRA';''',con=co) #Chart that picture the evolution of the emission in France print(df3) @@ -33,12 +33,20 @@ try : plt.show() - df4 = pd.read_sql('''SELECT max(emission)emission, year FROM CO_DEUX WHERE year BETWEEN 2000 AND 2017 AND code NOT LIKE 'OWID_WRL' GROUP BY year ORDER BY year;''',con=co) + df4 = pd.read_sql('''SELECT entity, year,emission FROM CO_DEUX WHERE emission = ANY(SELECT max(emission)emission FROM CO_DEUX WHERE year BETWEEN 2000 AND 2017 AND code NOT LIKE 'OWID_WRL' GROUP BY year) ORDER BY year;''',con=co) + + + + + + + print(df4) - fig = df4.plot(x='year', y='emission', legend=False, style='-') - fig.set_title("Plus gros pollueur de chaque annee") + fig = df4.plot(x='entity', y='emission', legend=False, style='-') + sns.barplot(data=df4 , x='year', y='emission', hue='entity') + fig.set_title("Plus gros pollueur de chaque annee, de 2000 à 2017") fig.set_xlabel("code du pays") - fig.set_ylabel("annee") + fig.set_ylabel("emissions (en tonnes)") fig.set_xticks(df4.index) fig.set_xticklabels(df4['year'], rotation='45') plt.show() @@ -52,8 +60,6 @@ try : fig.set_ylim(0) plt.show() - - plt.show() df6 = pd.read_sql('''SELECT * FROM CO_DEUX WHERE code LIKE 'CHN' AND year BETWEEN 1980 AND 2017;''',con=co) @@ -84,6 +90,7 @@ try : + except (Exception, psy.DatabaseError) as error : print(error)