SZÉKELYDATA Erdők

Székelyföldi adatskálázó munkafüzet

In [503]:
import numpy as np, requests, zipfile, StringIO, pandas as pd, json, copy

#suppres warnings
import warnings
warnings.simplefilter(action = "ignore")
In [504]:
import matplotlib.pyplot as plt
%matplotlib inline

Model zip betöltése D3plus formátumra

In [505]:
z = zipfile.ZipFile('../zips2/183.zip')   #romania
ro=json.loads(z.open('data.json').read())

INSSE adatok betöltése - a kódok alapján megkereshetjük a fileokat az insse.ro adatbázisban

In [506]:
df=pd.read_csv('../db/exportPivot_AGR306A.csv')
dfe=pd.read_csv('../db/exportPivot_EXP101J.csv') #exports
dfi=pd.read_csv('../db/exportPivot_EXP102J.csv') #imports

Formázás

In [507]:
dfe=dfe.set_index(['Judete',' Sectiuni si capitole conform Nomenclatorului Combinat (NC)',' Luni'])

Székelyföldi megyék részesedése a romániai fa-exportban

In [508]:
#u' IX. Produse din lemn  exclusiv mobilier', u' X. Hirtie si articole din acestea'
for i in dfe.loc['TOTAL'].loc[' IX. Produse din lemn  exclusiv mobilier'].T:
    print i,'HR',1.0*dfe.loc['Harghita'].loc[' IX. Produse din lemn  exclusiv mobilier'].loc[i][' Valoare']/\
    dfe.loc['TOTAL'].loc[' IX. Produse din lemn  exclusiv mobilier'].loc[i][' Valoare'],
    print 'CV',1.0*dfe.loc['Covasna'].loc[' IX. Produse din lemn  exclusiv mobilier'].loc[i][' Valoare']/\
    dfe.loc['TOTAL'].loc[' IX. Produse din lemn  exclusiv mobilier'].loc[i][' Valoare'],
    print 'MS',1.0*dfe.loc['Mures'].loc[' IX. Produse din lemn  exclusiv mobilier'].loc[i][' Valoare']/\
    dfe.loc['TOTAL'].loc[' IX. Produse din lemn  exclusiv mobilier'].loc[i][' Valoare']
 Luna ianuarie 2011 HR 0.0224271935574 CV 0.00655492087274 MS 0.0333270905515
 Luna februarie 2011 HR 0.0254174397032 CV 0.00856215213358 MS 0.0292764378479
 Luna martie 2011 HR 0.0226030626995 CV 0.00759877244653 MS 0.0313381724295
 Luna aprilie 2011 HR 0.0267161963831 CV 0.00700657540153 MS 0.0240876941319
 Luna mai 2011 HR 0.0307033677439 CV 0.00655078225889 MS 0.0421691933224
 Luna iunie 2011 HR 0.0268270261989 CV 0.00803585108013 MS 0.0258771257852
 Luna iulie 2011 HR 0.0291695937005 CV 0.00733528287399 MS 0.0374524186829
 Luna august 2011 HR 0.0215815556992 CV 0.00483516483516 MS 0.0414565826331
 Luna septembrie 2011 HR 0.0255098426591 CV 0.00680839676031 MS 0.0250297129454
 Luna octombrie 2011 HR 0.0269194810814 CV 0.00546270755584 MS 0.0394906624016
 Luna noiembrie 2011 HR 0.0247022907879 CV 0.0057949399144 MS 0.0322994104076
 Luna decembrie 2011 HR 0.0202294174154 CV 0.00762841159519 MS 0.029317586785
 Luna ianuarie 2012 HR 0.0173826479822 CV 0.00602394261939 MS 0.0247679335665
 Luna februarie 2012 HR 0.0213020052214 CV 0.00610083504601 MS 0.0254679775593
 Luna martie 2012 HR 0.015716680637 CV 0.00572560365573 MS 0.0324067814942
 Luna aprilie 2012 HR 0.0230295995357 CV 0.00573418456181 MS 0.0260166376475
 Luna mai 2012 HR 0.0194496393267 CV 0.00585092172055 MS 0.0257280256479
 Luna iunie 2012 HR 0.0225765632455 CV 0.00602272177238 MS 0.0318146301662
 Luna iulie 2012 HR 0.0248406787334 CV 0.00524115687398 MS 0.0435419186454
 Luna august 2012 HR 0.02309631325 CV 0.0044769887418 MS 0.0443059507609
 Luna septembrie 2012 HR 0.0276807868891 CV 0.00395970461941 MS 0.0442105106756
 Luna octombrie 2012 HR 0.029395750332 CV 0.00440239043825 MS 0.0365338645418
 Luna noiembrie 2012 HR 0.0206289223294 CV 0.00539847493083 MS 0.0467440448073
 Luna decembrie 2012 HR 0.0190066136979 CV 0.00569044342847 MS 0.0595144036575
 Luna ianuarie 2013 HR 0.0242325602423 CV 0.00612595506126 MS 0.0370269903703
 Luna februarie 2013 HR 0.0216503889964 CV 0.00691710351728 MS 0.0337951986311
 Luna martie 2013 HR 0.0211270157637 CV 0.00671015280546 MS 0.0475448450806
 Luna aprilie 2013 HR 0.021780825985 CV 0.00619340280871 MS 0.041441762418
 Luna mai 2013 HR 0.0242958761896 CV 0.00674685186965 MS 0.048958233202
 Luna iunie 2013 HR 0.0233000917864 CV 0.00669792364367 MS 0.0444977797623
 Luna iulie 2013 HR 0.0231212221626 CV 0.00553606727836 MS 0.0551207194031
 Luna august 2013 HR 0.0227467924578 CV 0.00537122923851 MS 0.0546041939192
 Luna septembrie 2013 HR 0.0261420797726 CV 0.00497410101539 MS 0.0558744880977
 Luna octombrie 2013 HR 0.0251061207329 CV 0.00628948929577 MS 0.0456218358167
 Luna noiembrie 2013 HR 0.025725442156 CV 0.00655258658092 MS 0.0590562233622
 Luna decembrie 2013 HR 0.0198799556524 CV 0.00530641893183 MS 0.0508926864702
 Luna ianuarie 2014 HR 0.0248313874405 CV 0.00817558376785 MS 0.0625070845613
 Luna februarie 2014 HR 0.020187160577 CV 0.00732311122056 MS 0.0531606029578
 Luna martie 2014 HR 0.0200751726348 CV 0.00712683196877 MS 0.0502899099677
 Luna aprilie 2014 HR 0.0204521054515 CV 0.0066086126685 MS 0.0492604079685
 Luna mai 2014 HR 0.0232729128815 CV 0.00777789255571 MS 0.048696899173
 Luna iunie 2014 HR 0.0213977203817 CV 0.00730170909496 MS 0.044422855587
 Luna iulie 2014 HR 0.0220302587225 CV 0.0067846589623 MS 0.0511388316193
 Luna august 2014 HR 0.0239906020916 CV 0.00726202009261 MS 0.0572646899529
 Luna septembrie 2014 HR 0.0284905625012 CV 0.00792862364342 MS 0.0551254896815
 Luna octombrie 2014 HR 0.0236894207851 CV 0.00693594965762 MS 0.048848001816
 Luna noiembrie 2014 HR 0.0247485396288 CV 0.00721717189174 MS 0.0525664512115
 Luna decembrie 2014 HR 0.0221377066479 CV 0.00880818384336 MS 0.0522921796225
 Luna ianuarie 2015 HR 0.0239824743457 CV 0.00950507321573 MS 0.0358007609824
 Luna februarie 2015 HR 0.0261952331941 CV 0.0115907516162 MS 0.0569110613308
 Luna martie 2015 HR 0.0277933548297 CV 0.0105378756017 MS 0.0440908453666
 Luna aprilie 2015 HR 0.024024385836 CV 0.00897601175918 MS 0.0435065482717
 Luna mai 2015 HR 0.0281244256843 CV 0.00834128729717 MS 0.0475815009574
 Luna iunie 2015 HR 0.0282860521598 CV 0.00799816894066 MS 0.04902534237
 Luna iulie 2015 HR 0.0265389308944 CV 0.00739743605873 MS 0.0547951237309
 Luna august 2015 HR 0.028574188132 CV 0.00547560495405 MS 0.0558481986969
 Luna septembrie 2015 HR 0.0337950641603 CV 0.0070761471671 MS 0.0693434481024
 Luna octombrie 2015 HR 0.0301896785726 CV 0.00742162931577 MS 0.0561422092754
 Luna noiembrie 2015 HR 0.0293392487513 CV 0.00768627561798 MS 0.0679401770387
 Luna decembrie 2015 HR 0.0259722125253 CV 0.00882031231818 MS 0.0717804308533
 Luna ianuarie 2016 HR 0.030836160447 CV 0.00831770105767 MS 0.0461624426262
 Luna februarie 2016 HR 0.0303034698851 CV 0.00797841476152 MS 0.06973859812
 Luna martie 2016 HR 0.0281013760439 CV 0.00991464042112 MS 0.0522118289642
 Luna aprilie 2016 HR 0.0316446538931 CV 0.00968010858257 MS 0.0584182495883
 Luna mai 2016 HR 0.0348571310851 CV 0.00923617835095 MS 0.0520247488378
 Luna iunie 2016 HR 0.032906018948 CV 0.00800511652751 MS 0.0588611509376
 Luna iulie 2016 HR 0.0298795033335 CV 0.00815034558689 MS 0.058841519359
 Luna august 2016 HR 0.0321754442132 CV 0.00708149435539 MS 0.056621464017
 Luna septembrie 2016 HR 0.0318455330088 CV 0.00813551046199 MS 0.0520012063246
 Luna octombrie 2016 HR 0.0343886502821 CV 0.00824595933359 MS 0.0524170831108
 Luna noiembrie 2016 HR 0.0301718410138 CV 0.00830180233737 MS 0.0562242535722
 Luna decembrie 2016 HR 0.0243680812211 CV 0.00874594811844 MS 0.0691899731768
In [509]:
dfi=dfi.set_index(['Judete',' Sectiuni si capitole conform Nomenclatorului Combinat (NC)',' Luni'])

Szkelyföldi megyék részesedése a romániai fa-importban

In [510]:
#u' IX. Produse din lemn  exclusiv mobilier', u' X. Hirtie si articole din acestea'
for i in dfi.loc['TOTAL'].loc[' IX. Produse din lemn  exclusiv mobilier'].T:
    print i,'HR',1.0*dfi.loc['Harghita'].loc[' IX. Produse din lemn  exclusiv mobilier'].loc[i][' Valoare']/\
    dfi.loc['TOTAL'].loc[' IX. Produse din lemn  exclusiv mobilier'].loc[i][' Valoare'],
    print 'CV',1.0*dfi.loc['Covasna'].loc[' IX. Produse din lemn  exclusiv mobilier'].loc[i][' Valoare']/\
    dfi.loc['TOTAL'].loc[' IX. Produse din lemn  exclusiv mobilier'].loc[i][' Valoare'],
    print 'MS',1.0*dfi.loc['Mures'].loc[' IX. Produse din lemn  exclusiv mobilier'].loc[i][' Valoare']/\
    dfi.loc['TOTAL'].loc[' IX. Produse din lemn  exclusiv mobilier'].loc[i][' Valoare']
 Luna ianuarie 2011 HR 0.0150882392564 CV 0.00462526381966 MS 0.0258655530109
 Luna februarie 2011 HR 0.00908192734458 CV 0.00581395348837 MS 0.0185058519532
 Luna martie 2011 HR 0.0118738404453 CV 0.00485748018216 MS 0.0129532804857
 Luna aprilie 2011 HR 0.0143393192174 CV 0.00412087912088 MS 0.0169525596355
 Luna mai 2011 HR 0.0183294525046 CV 0.0061794734014 MS 0.0148068541405
 Luna iunie 2011 HR 0.0146931202681 CV 0.00389023550887 MS 0.0188826046623
 Luna iulie 2011 HR 0.0158473383062 CV 0.00281597315838 MS 0.0128815793415
 Luna august 2011 HR 0.0103055555556 CV 0.0035 MS 0.0214444444444
 Luna septembrie 2011 HR 0.0122058196947 CV 0.00446126469335 MS 0.0166169578185
 Luna octombrie 2011 HR 0.0146171758831 CV 0.00325449597396 MS 0.0188255758494
 Luna noiembrie 2011 HR 0.0131207633899 CV 0.00648765019056 MS 0.0224885811538
 Luna decembrie 2011 HR 0.0112385321101 CV 0.00416666666667 MS 0.015252293578
 Luna ianuarie 2012 HR 0.0148837627591 CV 0.00490129951886 MS 0.0161428121768
 Luna februarie 2012 HR 0.0168757298376 CV 0.00241081854824 MS 0.0150299468867
 Luna martie 2012 HR 0.0103677687346 CV 0.00466043024552 MS 0.0140488332039
 Luna aprilie 2012 HR 0.0111161731207 CV 0.00361427486712 MS 0.00920273348519
 Luna mai 2012 HR 0.00918192525966 CV 0.00364064675019 MS 0.0127958025485
 Luna iunie 2012 HR 0.0127011511348 CV 0.00464023320146 MS 0.0322734168179
 Luna iulie 2012 HR 0.0107425399028 CV 0.00607911172797 MS 0.0215405968078
 Luna august 2012 HR 0.0106688154714 CV 0.00467365028203 MS 0.0234004834811
 Luna septembrie 2012 HR 0.0145927463671 CV 0.00644156795702 MS 0.0149590914642
 Luna octombrie 2012 HR 0.0156167702518 CV 0.00821658063837 MS 0.0116664910987
 Luna noiembrie 2012 HR 0.0124338375771 CV 0.00873813774312 MS 0.00914529111466
 Luna decembrie 2012 HR 0.0154541026436 CV 0.00633219678519 MS 0.010184652172
 Luna ianuarie 2013 HR 0.0117589416952 CV 0.00649191572758 MS 0.00922750285808
 Luna februarie 2013 HR 0.0123246629443 CV 0.00606019338145 MS 0.0120522947024
 Luna martie 2013 HR 0.0179039602594 CV 0.00827928798123 MS 0.00883124051332
 Luna aprilie 2013 HR 0.0117710648009 CV 0.00507477028407 MS 0.00960903249054
 Luna mai 2013 HR 0.0129832844201 CV 0.00446599464081 MS 0.0106545872145
 Luna iunie 2013 HR 0.0121665465032 CV 0.00561763999039 MS 0.0105443403028
 Luna iulie 2013 HR 0.00989881817434 CV 0.00479859606789 MS 0.0110779017796
 Luna august 2013 HR 0.00581333333333 CV 0.00312 MS 0.00762666666667
 Luna septembrie 2013 HR 0.011824685031 CV 0.00557868887465 MS 0.0107836856716
 Luna octombrie 2013 HR 0.0134219373818 CV 0.00480668207607 MS 0.0217220004203
 Luna noiembrie 2013 HR 0.0117330725984 CV 0.00672207284283 MS 0.0118247372281
 Luna decembrie 2013 HR 0.0131701715352 CV 0.00383980478002 MS 0.0120577047298
 Luna ianuarie 2014 HR 0.0126795963537 CV 0.00956596766328 MS 0.0100161308474
 Luna februarie 2014 HR 0.0141433719979 CV 0.0054514067658 MS 0.0135376601351
 Luna martie 2014 HR 0.0110951536144 CV 0.00566021796063 MS 0.0114049167863
 Luna aprilie 2014 HR 0.0127064135885 CV 0.00367540888924 MS 0.00963482187393
 Luna mai 2014 HR 0.0142202312741 CV 0.00369830190645 MS 0.00984477549745
 Luna iunie 2014 HR 0.010272619518 CV 0.00434610825761 MS 0.0101935993678
 Luna iulie 2014 HR 0.01146007423 CV 0.00475332624314 MS 0.00996245089315
 Luna august 2014 HR 0.0103006213962 CV 0.00380675138555 MS 0.00962884173991
 Luna septembrie 2014 HR 0.00837772510736 CV 0.00603102339662 MS 0.0108886959379
 Luna octombrie 2014 HR 0.0147822023268 CV 0.00669011486337 MS 0.0223823695797
 Luna noiembrie 2014 HR 0.00898351648352 CV 0.00714285714286 MS 0.0165659340659
 Luna decembrie 2014 HR 0.0106129221834 CV 0.00649911847063 MS 0.0079510491928
 Luna ianuarie 2015 HR 0.0227017841971 CV 0.00645709430756 MS 0.0125743415463
 Luna februarie 2015 HR 0.012751201398 CV 0.00494211446046 MS 0.00813674093491
 Luna martie 2015 HR 0.0125846442338 CV 0.00433378476925 MS 0.00960516720492
 Luna aprilie 2015 HR 0.0127716499659 CV 0.00615866124839 MS 0.01060097428
 Luna mai 2015 HR 0.0133584239383 CV 0.00413530341046 MS 0.0101988662764
 Luna iunie 2015 HR 0.0101696328096 CV 0.00277164172884 MS 0.0101487933981
 Luna iulie 2015 HR 0.00961747338902 CV 0.00349546774098 MS 0.00957797657839
 Luna august 2015 HR 0.00920786815524 CV 0.00318979266348 MS 0.010653907496
 Luna septembrie 2015 HR 0.0100184601185 CV 0.00467271748327 MS 0.0167871702177
 Luna octombrie 2015 HR 0.0164782758691 CV 0.00551981654727 MS 0.0148953873004
 Luna noiembrie 2015 HR 0.015597772961 CV 0.00663011602703 MS 0.0140252454418
 Luna decembrie 2015 HR 0.0132198392696 CV 0.00437491083741 MS 0.0144086737363
 Luna ianuarie 2016 HR 0.0183323163452 CV 0.00711007348845 MS 0.0137691348526
 Luna februarie 2016 HR 0.0184867045115 CV 0.00655437705408 MS 0.0363011652226
 Luna martie 2016 HR 0.0199618607743 CV 0.00778530065257 MS 0.0250529225494
 Luna aprilie 2016 HR 0.016562014957 CV 0.00672005079723 MS 0.020900945393
 Luna mai 2016 HR 0.0202792011443 CV 0.00622861178004 MS 0.0319940610911
 Luna iunie 2016 HR 0.0183997476606 CV 0.0060631549434 MS 0.0162093015105
 Luna iulie 2016 HR 0.0175940926045 CV 0.00608446671439 MS 0.0151263986738
 Luna august 2016 HR 0.0142949513308 CV 0.00517274522482 MS 0.0219841672055
 Luna septembrie 2016 HR 0.022097631037 CV 0.00546816868262 MS 0.0176158092371
 Luna octombrie 2016 HR 0.0247827785737 CV 0.00638175153962 MS 0.0201871732376
 Luna noiembrie 2016 HR 0.0229986152176 CV 0.00782214903252 MS 0.0272091021371
 Luna decembrie 2016 HR 0.0147495755518 CV 0.00560271646859 MS 0.017253820034
In [511]:
df=df.set_index(['Categorii de paduri',u' Macroregiuni  regiuni de dezvoltare si judete',u' Ani'])

Szkelyföldi megyék részesedése a romániai fa-kitermelésben

In [512]:
for i in df.loc['Total'].loc[' TOTAL'].T:
    print i,'HR',1.0*df.loc['Total'].loc[' Harghita'].loc[i][' Valoare']/\
    df.loc['Total'].loc[' TOTAL'].loc[i][' Valoare'],
    print 'CV',1.0*df.loc['Total'].loc[' Covasna'].loc[i][' Valoare']/\
    df.loc['Total'].loc[' TOTAL'].loc[i][' Valoare'],
    print 'MS',1.0*df.loc['Total'].loc[' Mures'].loc[i][' Valoare']/\
    df.loc['Total'].loc[' TOTAL'].loc[i][' Valoare']
 Anul 1990 HR 0.0630788635954 CV 0.0285302420566 MS 0.0431377259895
 Anul 1991 HR 0.0564670841706 CV 0.0266955407717 MS 0.0441240546007
 Anul 1992 HR 0.0503491847732 CV 0.0319432982184 MS 0.0414791286678
 Anul 1993 HR 0.0466348311713 CV 0.0302191940077 MS 0.0376948943027
 Anul 1994 HR 0.045201319724 CV 0.0345616244659 MS 0.0339821203669
 Anul 1995 HR 0.0938049765795 CV 0.040578597957 MS 0.0396446748282
 Anul 1996 HR 0.0582978119744 CV 0.0995859031432 MS 0.0384711517027
 Anul 1997 HR 0.0885136299411 CV 0.0796085053589 MS 0.0427266774649
 Anul 1998 HR 0.094249327638 CV 0.0518747033697 MS 0.0415045087803
 Anul 1999 HR 0.0897864864668 CV 0.0362440862802 MS 0.0414197301376
 Anul 2000 HR 0.0792106239543 CV 0.0326713196637 MS 0.0399518365804
 Anul 2001 HR 0.0543462860637 CV 0.0265169310157 MS 0.0464120862322
 Anul 2002 HR 0.0605868242274 CV 0.0216381515098 MS 0.0300797773315
 Anul 2003 HR 0.0602162777462 CV 0.0253602132822 MS 0.0385046281041
 Anul 2004 HR 0.0565562782094 CV 0.0325311290766 MS 0.0447368883217
 Anul 2005 HR 0.0678884329953 CV 0.0348088544026 MS 0.0493130754947
 Anul 2006 HR 0.0609028309105 CV 0.0295077786279 MS 0.0484315225708
 Anul 2007 HR 0.0679967048777 CV 0.0281593725345 MS 0.0534877245092
 Anul 2008 HR 0.076565736384 CV 0.0265555595465 MS 0.0403661266956
 Anul 2009 HR 0.0588865550034 CV 0.0300062349046 MS 0.0428997754224
 Anul 2010 HR 0.0588408390028 CV 0.0301089950328 MS 0.0326337719814
 Anul 2011 HR 0.0551296444801 CV 0.0291526329858 MS 0.0468965517241
 Anul 2012 HR 0.0515638429449 CV 0.0302077437478 MS 0.0424134750435
 Anul 2013 HR 0.056814351134 CV 0.0324757158193 MS 0.0412818105912
 Anul 2014 HR 0.058291828076 CV 0.0353786900549 MS 0.0472181695203
 Anul 2015 HR 0.057083455118 CV 0.0298845757206 MS 0.030970986759

Székelyföldi szorzók hozzávetőleges kalibrálása (Maros és Hargita megyék csak részlegesen fekszenek Székelyföld területén)

In [513]:
#szekelyland territory ratios (km2)
#harghita county
hr=6639
#covasna county
cv=3710
#mures county
ms=6714
#szekelyland
szf=12000
hr_mul=0.9
mr_mul=(szf-hr_mul*hr-cv)*1.0/ms
print mr_mul
0.344787012213

Kitermelés, fenyő és lombhullató kategóriákra osztva

In [514]:
df=df.drop(df.columns[0],axis=1)
In [515]:
de=df.unstack(level=1)[' Valoare']
In [516]:
de['szf']=de[' Covasna']+hr_mul*de[' Harghita']+mr_mul*de[' Mures']
In [517]:
exp_c={}
exp_nc={}
for i in de.loc['Total'].T:
    y=int(i[5:])
    exp_c[y]=(1.0*de.loc['Rasinoase'].loc[i]['szf']+\
             1.0*de.loc[u'Diverse specii moi'].loc[i]['szf'])/\
            (de.loc['Rasinoase'].loc[i][' TOTAL']+\
             de.loc[u'Diverse specii moi'].loc[i][' TOTAL'])
    exp_nc[y]=(1.0*de.loc['Stejar'].loc[i]['szf']+\
             1.0*de.loc[u'Fag'].loc[i]['szf']+\
             1.0*de.loc[u'Diverse specii tari'].loc[i]['szf'])/\
            (de.loc['Stejar'].loc[i][' TOTAL']+\
             de.loc['Fag'].loc[i][' TOTAL']+\
             de.loc[u'Diverse specii tari'].loc[i][' TOTAL'])

Export, fa és papír kategóriákra osztva

In [518]:
dfe=dfe.drop(dfe.columns[0],axis=1)
In [519]:
dee=dfe.unstack(level=0)[' Valoare']
In [520]:
dee['szf']=dee['Covasna']+hr_mul*dee['Harghita']+mr_mul*dee['Mures']
In [521]:
#u' IX. Produse din lemn  exclusiv mobilier', u' X. Hirtie si articole din acestea'
exp_nonp={}
exp_pap={}
for i in dee.loc[u' IX. Produse din lemn  exclusiv mobilier'].T:
    y=int(i[-4:])
    if y not in exp_nonp:exp_nonp[y]=0
    exp_nonp[y]+=1.0/12*dee.loc[u' IX. Produse din lemn  exclusiv mobilier'].loc[i]['szf']/\
                    dee.loc[u' IX. Produse din lemn  exclusiv mobilier'].loc[i]['TOTAL']
    if y not in exp_pap:exp_pap[y]=0
    exp_pap[y]+=1.0/12*dee.loc[u' X. Hirtie si articole din acestea'].loc[i]['szf']/\
                    dee.loc[u' X. Hirtie si articole din acestea'].loc[i]['TOTAL']
In [522]:
miny2=min(exp_pap)

Import, fa és papír kategóriákra osztva

In [523]:
dfi=dfi.drop(dfi.columns[0],axis=1)
In [524]:
dei=dfi.unstack(level=0)[' Valoare']
In [525]:
dei['szf']=dei['Covasna']+hr_mul*dei['Harghita']+mr_mul*dei['Mures']
In [526]:
#u' IX. Produse din lemn  exclusiv mobilier', u' X. Hirtie si articole din acestea'
imp_nonp={}
imp_pap={}
for i in dei.loc[u' IX. Produse din lemn  exclusiv mobilier'].T:
    y=int(i[-4:])
    if y not in imp_nonp:imp_nonp[y]=0
    imp_nonp[y]+=1.0/12*dei.loc[u' IX. Produse din lemn  exclusiv mobilier'].loc[i]['szf']/\
                    dei.loc[u' IX. Produse din lemn  exclusiv mobilier'].loc[i]['TOTAL']
    if y not in imp_pap:imp_pap[y]=0
    imp_pap[y]+=1.0/12*dei.loc[u' X. Hirtie si articole din acestea'].loc[i]['szf']/\
                    dei.loc[u' X. Hirtie si articole din acestea'].loc[i]['TOTAL']
In [527]:
miny=min(imp_pap)
In [528]:
s=[]
for i in ro:
    k={}
    k['g']=i['g']
    k['item']=i['item']
    k['year']=i['year']
    k['partner']=i['partner']
    if i['g']=='m':
        if ' (C)' in i['item']:
            k['p']=i['p']*exp_c[i['year']]
            k['s']=i['s']*exp_c[i['year']]
        elif ' (NC)' in i['item']:
            k['p']=i['p']*exp_nc[i['year']]
            k['s']=i['s']*exp_nc[i['year']]
        elif 'News' in i['item']:
            k['p']=i['p']*exp_pap[max(miny2,i['year'])]
            k['s']=i['s']*exp_pap[max(miny2,i['year'])]
        else:
            k['p']=i['p']*exp_nonp[max(miny2,i['year'])]
            k['s']=i['s']*exp_nonp[max(miny2,i['year'])]
    else:
        if 'News' in i['item']:
            k['p']=i['p']*imp_pap[max(miny,i['year'])]
            k['s']=i['s']*imp_pap[max(miny,i['year'])]
        else:
            k['p']=i['p']*imp_nonp[max(miny,i['year'])]
            k['s']=i['s']*imp_nonp[max(miny,i['year'])]
    s.append(k)

Árbecslés

In [529]:
from jupyterthemes import jtplot

# you can select an alternative theme's plot style by name
# oceans16 | grade3 | chesterish | onedork | monokai | solarizedl
jtplot.style('solarized-light')
In [530]:
#arnormalizasa, fenyo, lombhullato es papir szamara
items={'c':{},'nc':{},'pp':{}}
items2={'c':{},'nc':{},'pp':{}}
for i in ro:
    if i['g']=='m': #export
        it='x'
        if '(C)' in i['item']: it='c'
        elif '(NC)' in i['item']: it='nc'
        elif 'News' in i['item']: it='pp'        
        if it!='x':
            if i['year'] not in items[it]: items[it][i['year']]=[]
            if i['p']*i['s']!=0:
                items[it][i['year']].append(i['s']*1.0/i['p'])
    else: #import
        it='x'
        if '(C)' in i['item']: it='c'
        elif '(NC)' in i['item']: it='nc'
        elif 'News' in i['item']: it='pp'        
        if it!='x':
            if i['year'] not in items2[it]: items2[it][i['year']]=[]
            if i['p']*i['s']!=0:
                items2[it][i['year']].append(i['s']*1.0/i['p'])
In [575]:
def reject_outliers(data, m = 2.):
    d = np.abs(data - np.median(data))
    mdev = np.median(d)
    s = d/mdev if mdev else 0.
    return data[s<m][data[s<m]>0]
In [576]:
yrs=[1997,2006,2014]
fig,ax=plt.subplots(3,3,figsize=(10,6))
me=1.4
sg=['pp','nc','c']
ti=[u'Papír',u'Lombhullató',u'Fenyõ']
uni=['$\$/tonna$','$\$/m^3$','$\$/m^3$']
for k in range(3):
    for ye in range(len(yrs)):
        year=yrs[ye]
        sq=sg[k]
        mn=np.median(reject_outliers(np.array(items[sq][year])))
        hs=np.histogram(items[sq][year]+items2[sq][year],bins=np.arange(0,me,0.1))
        ze=list(hs[0]*100.0/sum(hs[0]))+[0]
        ax[ye][k].bar(hs[1],ze,0.09,color='#fec44f')
        ax[ye][k].plot([mn,mn],[0,20],color='#993404')
        ax[ye][k].set_ylim(0,20)
        ax[ye][k].set_xlim(0,me)
        if k==2 and ye==0:
            ax[ye][k].text(mn,17,u' export-ármedián: '+str(int(mn*1000))+' '+uni[k],color='#993404',size=10)
        elif ye==0:
            ax[ye][k].text(mn,17,u' '+str(int(mn*1000))+' '+uni[k],color='#993404')
        else:
            ax[ye][k].text(mn,17,u' '+str(int(mn*1000+1)),color='#993404')
        if k!=0: 
            ax[ye][k].set_yticklabels([])
        if ye!=2: 
            ax[ye][k].set_xticklabels([])
        else:    
            ax[ye][k].set_xlabel(u'Ár ('+uni[k]+')')
        if k==0:
            if ye==1: 
                ax[ye][k].set_ylabel(u'Áreloszlás (%)\n'+str(year))
            else:
                ax[ye][k].set_ylabel(str(year))
        if ye==0: 
            ax[ye][k].set_title(ti[k],y=1.1)
        
        mn=np.median(reject_outliers(np.array(items2[sq][year])))
        hs=np.histogram(items2[sq][year],bins=np.arange(0,me,0.1))
        ze=list(hs[0]*100.0/sum(hs[0]))+[0]
        #ax[ye][k].bar(hs[1],ze,0.09,color='#cc4c02')
        ax[ye][k].plot([mn,mn],[0,15.5],color='#cc4c02',ls='--')
        if k==2 and ye==0:
            ax[ye][k].text(mn,13,u'    import-ármedián: '+str(int(mn*1000))+' '+uni[k],color='#cc4c02',size=10)
        else:
            ax[ye][k].text(mn,13,u' '+str(int(mn*1000)),color='#cc4c02',size=10)
        if k!=0: 
            ax[ye][k].set_yticklabels([])
        if ye!=2: 
            ax[ye][k].set_xticklabels([])
        else:    
            ax[ye][k].set_xlabel(u'Ár ('+'$1000$ '+uni[k]+')')
        if k==0:
            if ye==1: 
                ax[ye][k].set_ylabel(u'Tranzakciók %-a\n'+str(year))
            else:
                ax[ye][k].set_ylabel(str(year))
        if ye==0: 
            ax[ye][k].set_title(ti[k],y=1.1)
        plt.suptitle(u'Románia nemzetközi fakereskedelmének áreloszlása',y=1.02,fontsize=14)
In [544]:
colors=['#fec44f','#cc4c02','#662506']
for k in range(3):
    sq=sg[k]
    x=[]
    y=[]
    for i in np.sort(items[sq].keys()):
        x.append(i) 
        mn=np.median(reject_outliers(np.array(items[sq][i])))
        y.append(mn*1000)
    plt.plot(x,y,label=ti[k]+'-export',c=colors[k],lw=2)
plt.legend(loc=2,framealpha=0,fontsize=10)
plt.ylabel(u'Exportár '+'\nFa: $\$/m^3$ | '+u'Papír: '+'$\$/tonna$ ')
plt.ylim(0,2000)
ax=plt.gca().twinx()
for k in range(3):
    sq=sg[k]
    x=[]
    y=[]
    for i in np.sort(items2[sq].keys()):
        x.append(i) 
        mn=np.median(reject_outliers(np.array(items2[sq][i])))
        y.append(mn*1000)
    ax.plot(x,y,label=ti[k]+'-import',ls='--',c=colors[k],lw=2)
    ax.set_ylim(0,2000)
ax.legend(loc=1,framealpha=0,fontsize=10)
ax.set_ylabel('Fa: $\$/m^3$ | '+u'Papír: '+'$\$/tonna$ '+u'\nImportár ')
plt.title(u'Románia nemzetközi fakereskedelmének árváltozásai',y=1.1)
plt.show()
In [534]:
#methid 2
q=[]
for i in ro:
    k={}
    k['g']=i['g']
    k['item']=i['item']
    k['year']=i['year']
    k['partner']=i['partner']
    if i['g']=='m':
        if ' (C)' in i['item']:
            k['p']=i['p']*exp_c[i['year']]
            k['s']=i['p']*exp_c[i['year']]*np.median(reject_outliers(np.array(items['c'][i['year']])))
        elif ' (NC)' in i['item']:
            k['p']=i['p']*exp_nc[i['year']]
            k['s']=i['p']*exp_nc[i['year']]*np.median(reject_outliers(np.array(items['nc'][i['year']])))
        elif 'News' in i['item']:
            k['p']=i['p']*exp_pap[max(miny2,i['year'])]
            k['s']=i['p']*exp_pap[max(miny2,i['year'])]*np.median(reject_outliers(np.array(items['pp'][i['year']])))
        else:
            k['p']=i['p']*exp_nonp[max(miny2,i['year'])]
            k['s']=i['p']*exp_nonp[max(miny2,i['year'])]*np.median(reject_outliers(np.array(items['pp'][i['year']]+\
                                                                  items['nc'][i['year']]+\
                                                                  items['c'][i['year']])))
    else:
        if 'News' in i['item']:
            k['p']=i['p']*imp_pap[max(miny,i['year'])]
            k['s']=i['p']*imp_pap[max(miny,i['year'])]*np.median(reject_outliers(np.array(items2['pp'][i['year']])))
        else:
            k['p']=i['p']*imp_nonp[max(miny,i['year'])]
            k['s']=i['p']*imp_nonp[max(miny,i['year'])]*np.median(reject_outliers(np.array(items2['c'][i['year']]+\
                                                                 items2['nc'][i['year']])))
    q.append(k)

Globális JSON könyvtárak frissítése

In [535]:
try:
    import zlib
    compression = zipfile.ZIP_DEFLATED
except:
    compression = zipfile.ZIP_STORED
In [536]:
file('dummy.json','w').write(json.dumps(s)) 
zf = zipfile.ZipFile('../zips2/999.zip', mode='w')
zf.write('dummy.json','data.json',compress_type=compression)
zf.close()
file('dummy.json','w').write(json.dumps(q)) 
zf = zipfile.ZipFile('../zips2/899.zip', mode='w')
zf.write('dummy.json','data.json',compress_type=compression)
zf.close()
In [537]:
c=json.loads(file('../json/countries2.json').read())
if u'Székelyföld (skálázott)' not in c:
    c.append(u'Székelyföld (skálázott)')
if u'Székelyföld (becsült)' not in c:
    c.append(u'Székelyföld (becsült)')
file('../json/countries3.json','w').write(json.dumps(c)) 
In [538]:
d=json.loads(file('../json/cdict2.json').read())
d[u'Székelyföld (skálázott)']=999
d[u'999']=u'Székelyföld (skálázott)'
d[u'Székelyföld (becsült)']=899
d[u'899']=u'Székelyföld (becsült)'
file('../json/cdict3.json','w').write(json.dumps(d)) 
In [539]:
e=json.loads(file('../json/hnames.json').read())
e[u'Székelyföld (skálázott)']=u'Székelyföld (skálázott)'
e[u'Székelyföld (becsült)']=u'Székelyföld (becsült)'
file('../json/hnames3.json','w').write(json.dumps(e)) 
In [540]:
file('../json/szf.json','w').write(json.dumps(s)) 
In [541]:
file('../json/items.json','w').write(json.dumps(items)) 
file('../json/items2.json','w').write(json.dumps(items2)) 

Grafikon

In [ ]:
x=[]
y=[]
for i in np.sort(exp_c.keys()):
    x.append(i)
    y.append(exp_c[i]*100)
plt.plot(x,y,label=u'Fenyõ-kitermelés')
x=[]
y=[]
for i in np.sort(exp_nc.keys()):
    x.append(i)
    y.append(exp_nc[i]*100)
plt.plot(x,y,label=u'Lomhullató-kitermelés')
x=[]
y=[]
for i in np.sort(imp_pap.keys()):
    x.append(i)
    y.append(imp_pap[i]*100)
plt.plot(x,y,label=u'Papír-import')
x=[]
y=[]
for i in np.sort(imp_nonp.keys()):
    x.append(i)
    y.append(imp_nonp[i]*100)
plt.plot(x,y,label=u'Fa-import')
x=[]
y=[]
for i in np.sort(exp_pap.keys()):
    x.append(i)
    y.append(exp_pap[i]*100)
plt.plot(x,y,label=u'Papír-export')
x=[]
y=[]
for i in np.sort(exp_nonp.keys()):
    x.append(i)
    y.append(exp_nonp[i]*100)
plt.plot(x,y,label=u'Fa-export')
plt.xlim(1990,2015)
plt.ylabel(u'Országos kereskdelem %-a')
plt.legend(framealpha=0,fontsize=10.4)
plt.title(u'Székelyföld részesedése\nRománia fa-kereskedelmében')
Out[ ]:
<matplotlib.text.Text at 0xd9d19b0>