<jupyter_start><jupyter_text><NAME>/ Final Project:Data Bootcamp / Professor Backus / 05.05.2016 OBJECTIVE: This project will address the relation between livestock production (beef in this example) and total CO2 emissions. This project tries to find a relation, or lack of, between the two variables. In summation we will see the relation of magnitude of such production (livestock) and the total emissions of a country(that contriubute to global warming).DATA REPORT:Data was accessed from various sources including World Bank, FAOSTAT, etc. To access the information, certain parameters such as skipcolumns and na_values were required. For simplicity and clarity, we renamed columns and labels and created dataframes with the relvant data. Although all the datasets include the same list of countries, the order is different. To consolidate the information, merge methods must be used to correctly aquire the data. Many countries are too small to report an actual number or the data is simply unavailable, nevertheless na-values must be cleaned to avoid errors. The effect of na-values on the model was neutralized by multiplying Population and Per Capita Emissions to get to Total Emissions. This creates a value of 0 for size for the respective bubbles that have na-values, removing them from the model. Finally, only those countries with accurate data remain in the model. An additional note: Beef Production statistics were used as this is one of the most traded livestock or agriculture product, and also has the reputation for adding to greenhouse gases more than other livestock. Knowing this, the same results can be achieved using different livestock products like chicken, goat or fish, except some countries that do not actively produce or trade this product may be excluded or misrepresented.<jupyter_code># -*- coding: utf-8 -*-
"""
Created on Thu Apr 21 20:05:18 2016

@author: Yash
"""

import pandas as df
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
path='C://Users//Yash//data.DataBoot//BeefStats1.csv'##please download this file from http://faostat3.fao.org/download/Q/QL/E. Select ALL Countries, 
##Items Aggregated :Beef and Buffalo Meat + (Total) and selct year 2011.Download the cvs file and paste the location here.
x1=df.read_csv(path,usecols={3,9},na_values="")
x1=x1.set_index("AreaName")
beef=df.DataFrame(x1["Value"])
path1='http://api.worldbank.org/v2/en/indicator/sp.pop.totl?downloadformat=excel'
y=df.read_excel(path1,skiprows=3,sheetname='Data',na_values="")
pop=y.set_index("Country Name")
pop=df.DataFrame(pop["2011"])
path2='http://api.worldbank.org/v2/en/indicator/en.atm.co2e.pc?downloadformat=excel'
y2=df.read_excel(path2,skiprows=3,sheetname='Data',na_values="")
y2=y2.set_index("Country Name")
em=df.DataFrame(y2["2011"])
real=df.merge(em,beef,how='right',right_index=True, left_index=True)
real1=df.merge(real,pop,how='right',right_index=True, left_index=True)
real1.columns=['Emissions Per Capita','Beef','Population']
real1['Total Emissions']=real1['Emissions Per Capita']*real1['Population']
print("Select Data Samples:",sep='\t')
print(real1.head(n=3))
print(real1.tail(n=3))
area=np.pi*(0.000001*real1['Population'])    ##size of bubble is level of consumption
fig, ax = plt.subplots()
ax.scatter(real1['Total Emissions'],real1['Beef'],alpha=0.6, s=(0.00002*real1['Population']),c=np.random.rand(248))
ax.set_ylabel('Beef Production')
ax.set_xlabel('Total Emissions')
ax.text(35000000,300000, 'Bubble size represents Population',horizontalalignment='right')
ax.set_ylim(1,400000)
ax.set_xlim(1,39000000)
print("Beef Production Statistics:",real1['Beef'].quantile(q=[0.25, 0.5, 0.75]))
ax.set_title('Exhibit 1-Global: Beef Production vs. CO2 Emissions(in metric tonnes)', loc='left', fontsize=14)
fig, ax = plt.subplots()
ax.scatter(real1['Total Emissions'],real1['Beef'],alpha=0.6, s=(0.00009*real1['Population']),c=np.random.rand(248))
ax.set_ylabel('Beef Production')
ax.set_xlabel('Total Emissions')
ax.text(14000000,170000, 'Bubble size represents Population',horizontalalignment='right')
ax.set_ylim(1,200000)
ax.set_xlim(1,13000000)
ax.set_title('Exhibit 2-Developed Countries(lower emissions/higher beef imports): Beef Production vs. CO2 Emissions(in metric tonnes)', loc='left', fontsize=14)<jupyter_output>Select Data Samples:
              Emissions Per Capita      Beef  Population  Total Emissions
Country Name                                                             
Aruba                          NaN       NaN    101936.0              NaN
Andorra                        NaN       NaN     82326.0              NaN
Afghanistan               0.425262  138000.0  28809167.0       12251447.0
                  Emissions Per Capita      Beef  Population  Total Emissions
Country Name                                                                 
Congo, Dem. Rep.                   NaN       NaN  68087376.0              NaN
Zambia                        0.212450  153970.0  14343526.0        3047277.0
Zimbabwe                      0.691698  101920.0  14255592.0        9860563.0
Beef Production Statistics: 0.25      7950.00
0.50     55395.50
0.75    198532.75
Name: Beef, dtype: float64
{'fraction_non_alphanumeric': 0.10248986682107701, 'fraction_numerical': 0.06292221578845783, 'mean_word_length': 3.925855513307985, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '422147', 'license': 'MIT', 'n_tokens_mistral': 1748, 'n_tokens_neox': 1519, 'n_words': 495, 'path': 'UG_S16/Yash_Patil_bootcamp_project.ipynb', 'repo_name': 'NYUDataBootcamp/Projects', 'size': '5186'}