In [1]:
import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
pd.set_option('display.notebook_repr_html', True)
pd.set_option('display.max_columns', 100)
pd.set_option('display.max_rows', 1000)
pd.set_option('display.width', 5000)
pd.set_option('display.mpl_style', 'default') # Make the graphs a bit prettier
plt.rcParams['figure.figsize'] = (15, 7)
from tedutil import isozygio
db = '/home/tedlaz/tmp/samaratot/el1115.sql3'
sql = """select tr.dat as dat, substr(lmo.lmo,1,{0}) as lmo, trd.xr, trd.pi
from trd
inner join tr on tr.id=trd.id_tr
inner join lmo on lmo.id=trd.id_lmo
Where lmo.lmo like '{1}%'"""
In [2]:
def calc(lmo, lsize=2, period='y', multiplier=False):
sqf = sql.format(lsize, lmo)
aa, stt = isozygio.arr(db, sqf, period)
asd = pd.DataFrame(aa)
asd.columns = stt
asd.set_index('Lmoi', inplace=True)
asd.index.name = None
asd = asd.replace('-', 'NaN', regex=True).astype('float')
if multiplier:
return asd.T * -1
else:
return asd.T
In [3]:
om6 = calc(6)['6']
om6
Out[3]:
In [4]:
om6.plot(kind='bar')
Out[4]:
In [5]:
om7 = calc(7, multiplier=True)['7']
om7
Out[5]:
In [6]:
om7.plot(kind='bar')
Out[6]:
In [7]:
om2 = calc(2, multiplier=False)['2']
om2
Out[7]:
In [8]:
om2.plot(kind='bar')
Out[8]:
In [9]:
kpol = pd.Series([356850.21, 537000.12, 182606.41, 107805.77, 127020.26], index=['2011', '2012', '2013', '2014', '2015'])
kerdi = om7 - om6 - kpol
ejoda = om6 + kpol
df = pd.DataFrame({'esoda': om7, 'ejoda': ejoda, 'kerdi': kerdi, 'om6': om6, 'om2': om2, 'kpol': kpol})
df[['esoda', 'ejoda', 'kerdi', 'om6','om2', 'kpol']]
Out[9]:
In [10]:
df[['esoda', 'ejoda', 'kerdi', 'om6', 'kpol']].plot(kind='bar')
Out[10]:
In [ ]: