In [13]:
import matplotlib.pyplot as plt
import matplotlib
import os
import pandas as pd
import numpy as np
%matplotlib inline
matplotlib.style.use('ggplot')
import datetime
import locale
import time
locale.setlocale(locale.LC_TIME, 'es_ES.UTF-8')
import glob
In [14]:
product = 'acelga/'
pro = 'production/'
imp = 'export/'
pwd = '/Volumes/Macintosh HD/_GitHub/journey-of-food/data/producto/'
aux = '/Volumes/Macintosh HD/_GitHub/journey-of-food/data/aux/'
dwd = '/Volumes/Macintosh HD/_GitHub/journey-of-food/data/source/'
In [15]:
os.chdir(dwd)
files = os.listdir(dwd)
files
Out[15]:
In [16]:
data = pd.read_excel(files[1], sheetname='2015', encoding ='utf-8',index_col=0,na_values='x')
data.fillna(0,inplace=True)
In [17]:
data.head()
Out[17]:
In [18]:
data.drop('%cuota',axis=0,inplace=True)
data.drop('TOTAL HORTALIZAS',axis=0,inplace=True)
data.drop('OTRAS HORTALIZAS',axis=0,inplace=True)
data.drop('OTROS CÍTRICOS',axis=0,inplace=True)
data.drop('OTRAS FRUTAS',axis=0,inplace=True)
data.drop('TOTAL FRUTAS',axis=0,inplace=True)
data.drop('TOTAL F. Y H.',axis=0,inplace=True)
data.drop('TOTAL',axis=1,inplace=True)
data.drop('TOTAL UE-27',axis=1,inplace=True)
data.drop('T. HORTALIZAS',axis=0,inplace=True)
data.drop('* Datos provisionales',axis=0,inplace=True)
In [19]:
data = data.loc[pd.notnull(data.index)]
In [20]:
data.index = [x.lower() for x in data.index.values.tolist()]
In [21]:
data.loc[data.index=='acelga'].transpose().sort_values('acelga',ascending=False).sum()
Out[21]:
In [22]:
for producto in data.index.values:
datos = data.loc[data.index==producto].transpose().sort_values(producto,ascending=False)
datos.columns = ['Exportado']
datosSum = pd.DataFrame(datos.sum())
datosSum.columns = ['Ton']
datos['Percent'] = datos['Exportado']/datos['Exportado'].sum()*100.0
datos.Percent = datos.Percent.round(2)
datos.index.name = 'Pais'
datosSum.index.name = 'Total'
try:
datos[:3].to_csv(pwd+producto+'/'+producto+'_export_country.csv')
datosSum.to_csv(pwd+producto+'/'+producto+'_export_total.csv')
except:
datos[:3].to_csv(pwd+producto+'_export_country.csv')
datosSum.to_csv(pwd+producto+'_export_total.csv')
In [23]:
data.head()
Out[23]:
In [24]:
names = pd.read_csv(aux+'map_names_import.csv',index_col=1)
In [390]:
In [ ]: