<jupyter_start><jupyter_text><jupyter_code>import pandas as pd
import numpy as np
from google.colab import files
uploaded = files.upload()
column_headers = ['Country Code', 'Country Name', 'Year', 'Series', 'Value', 'Footnotes', 'Source']

import io
df = pd.read_csv(io.BytesIO(uploaded['SYB60_312_Carbon Dioxide Emission Estimates.csv']), header=None, names=column_headers, skiprows=2, na_filter=False)
df.head()
print(df.shape)

df.head(30)
df.dtypes


df["Value"] = df["Value"].str.replace(",", "").astype(float)
import matplotlib.pyplot as plt
co2_output_overtime = pd.concat([df.Year, df.Value], axis=1)

co2_output_overtime.head(20)
%matplotlib inline
from matplotlib.ticker import AutoMinorLocator, MultipleLocator, FuncFormatter
from matplotlib.patches import Circle
from matplotlib.patheffects import withStroke
import seaborn as sns


co = sns.catplot(x='Year', y='Value', kind='bar', data=co2_output_overtime)
co.set_axis_labels("","Thousand Metric Tons")
co.set(xlabel='Year')
co.fig.suptitle("Total World CO2 Emission Estimates", fontweight='bold', fontsize=14, x=.65, y=1.05)
plt.show()

df2 = df.drop(columns=['Country Code', 'Series', 'Footnotes', 'Source'])

df2.head(20)
df2.iloc[0:8, 2].sum()
ind_countries = df[df["Country Name"] != "Total, all countries or areas"]
gb = ind_countries.groupby("Country Name")
# gb.first()
highest_20 = gb.sum().sort_values(by='Value', ascending=False)[0:20]
highest_20
new_highest_20 = highest_20.drop(columns=['Country Code', 'Year'])
new_highest_20

ind_countries = df[df["Country Name"] != "Total, all countries or areas"]
gb = ind_countries.groupby("Country Name")
# gb.first()
lowest_200 = gb.sum().sort_values(by='Value', ascending=False)[20:225]
lowest_200
lowest_200 = lowest_200.drop(columns=['Country Code', 'Year'])
lowest_200
lowest_200.dtypes
lowest_200 = lowest_200.reset_index()
lowest_200.Value.sum()
new_highest_20.Value.mean()
df2.Value.mean()
new_highest_20.Value.sum()
df2.Value.sum()
new_highest_20 = new_highest_20.reset_index()
new_highest_20.isna().sum()

y = new_highest_20.Value


ax = sns.barplot(x='Value', y='Country Name', data=new_highest_20)
plt.gcf().set_size_inches(14,5)
ax.set_title('Top 20 CO2 Emission Producing Countries', x=.162, y=1.06)
ax.text(s='Total CO2 Emission between 1975 - 2014', x=0, y=-1)
ax.set(xlabel='CO2 Emission Per Thousand Metric Tons', ylabel='Country')
ax.set_xticklabels(['0', '1000', '2000', '3000', '4000', '5000'], rotation='horizontal')
#plt.show()
for i, v in enumerate(y):
    ax.text(v, i, str(v), color='steelblue', fontsize=6, fontweight='bold')

sum_of_top20 = new_highest_20.Value.sum()
sum_of_rest_world = lowest_200.Value.sum()
sum_of_world = (sum_of_top20 + sum_of_rest_world)

Co_comparison = {'Top_20_Countries':[sum_of_top20],
                 'Rest_of_world': [sum_of_rest_world],
                 'Total_world_CO2_Emission': [sum_of_world]}

df3 = pd.DataFrame(Co_comparison, columns= ['Top_20_Countries', 'Rest_of_world'])
df4 = pd.DataFrame(Co_comparison, columns= ['Top_20_Countries', 'Rest_of_world', 'Total_world_CO2_Emission'])
df3.head()



df4.head()
sizes = [81.5, 18.5]
labels = 'Top 20 Countries', 'The Rest of the World'
explode = (0.1, 0)
fig1, df3 = plt.subplots()
colors = ['lightblue', 'lightsteelblue']
df3.set_title('CO2 Emission between Top 20 Developed Countries & The Rest of the World', fontweight='bold')
df3.text(s='Total CO2 Emission between 1975 - 2014', x=-2.67, y=1.09)
df3.pie(sizes, explode=explode, labels=labels, colors=colors, shadow=True, autopct='%1.1f%%')
df3.axis('equal')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.162109375, 'fraction_numerical': 0.054966517857142856, 'mean_word_length': 6.6931330472103, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '188678', 'license': 'MIT', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1351, 'n_words': 278, 'path': 'Loc_Huynh_Buildweek1.ipynb', 'repo_name': 'lochuynhk/lochuynhk.github.io', 'size': '3584'}