Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created November 9, 2020 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/056a6e063d5a06a695706f2a74a71fdb to your computer and use it in GitHub Desktop.
Save amankharwal/056a6e063d5a06a695706f2a74a71fdb to your computer and use it in GitHub Desktop.
import numpy as np # linear algebra
import pandas as pd # data processing
import matplotlib.pyplot as plt
food_data=pd.read_csv("FoodFacts.csv",low_memory=False)
#Searching for manufacturers which use plastic stuffs for packing food
df=food_data[['manufacturing_places','packaging_tags']][(food_data['packaging_tags']=='plastique')|(food_data['packaging_tags']=='plastic')]
df=df.dropna()
print(df.head(20))
#Calculating which country uses what extent of platic stuffs
data=df['manufacturing_places'].value_counts(sort=True,dropna=False)
print(data.head(10))
#Defining a new column stating the extent of usage of plastic as 1
df['value']=1
def plast(country):
return df[df.manufacturing_places == country].value.sum()
#Plastic Extent for some of the highest users
fr_plast=plast('France')
ge_plast=plast('Germany')
au_plast=plast('Australia')
us_plast=plast('United States')
iy_plast=plast('Italy')
al_plast=plast('Allemagne')
ch_plast=plast('China')
uk_plast=plast('United Kingdom')
countries=['FR','GE','AU','US','IY','AL','CH','UK']
plastic=[fr_plast,ge_plast,au_plast,us_plast,iy_plast,al_plast,ch_plast,uk_plast]
ypos=np.arange(len(countries))
plt.bar(ypos,plastic,align='center',alpha=0.5,facecolor='r')
plt.xticks(ypos, countries)
plt.annotate('Biggest user',xy=(3,146),xytext=(5,120),arrowprops=dict(facecolor='blue'))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment