In [1]:
import pandas as pd
cols = ('Notional', 'Tenor', 'Ccy', 'Cpty')
data = [[ 1e7, 6, 'USD', 'JPM'],
[ 20e6, 3, 'GBP', 'GS'],
[1.2e6, 1, 'USD', 'JPM'],
[2.5e9, 1, 'JPY', 'BA'],
[1.2e7, 1, 'GBP', 'GS']]
df = pd.DataFrame(data, columns=cols)
df
Out[1]:
In [2]:
# Slicing in different directions
df.loc[:, 'Tenor':'Ccy']
Out[2]:
In [3]:
df.loc[:, ['Tenor','Ccy']]
Out[3]:
In [4]:
df.loc[1:3, :]
Out[4]:
In [5]:
df.iloc[3]
Out[5]:
In [6]:
# Mutable setting. Note it is column, row, value (rather than row, column)
df.set_value(4, 'Tenor', 2)
Out[6]:
In [7]:
# merge is the function to join tables
rates = pd.DataFrame({'Ccy': ['USD', 'GBP', 'JPY'], 'Rate': [1, 0.64, 124.89]})
usd_all = pd.merge(df, rates, on='Ccy')
usd_all['USD_Notional'] = usd_all.Notional / usd_all.Rate
usd_all
Out[7]:
In [ ]: