Insert line stations V2 in lookup table


In [1]:
import os
import re
import pickle
import time
import datetime

import numpy as np
import pandas as pd

import seaborn as sns
import matplotlib.pyplot as plt

from scipy.sparse import csr_matrix

%matplotlib inline

# Custom modules
import const
import func

Load data


In [2]:
lut = pd.read_csv(const.LOOK_UP_TABLE)
lut.set_index('station_V2', inplace=True)
lut.head(3)


Out[2]:
line station feature_nr feat_nr_dat name_dat name_cat name_num col_dat col_num col_cat line_V2
station_V2
0.0 0 0 0 1.0 L0_S0_D1 NaN L0_S0_F0 0.0 0.0 NaN 1.0
0.0 0 0 2 3.0 L0_S0_D3 NaN L0_S0_F2 1.0 1.0 NaN 1.0
0.0 0 0 4 5.0 L0_S0_D5 NaN L0_S0_F4 2.0 2.0 NaN 1.0

Insert new line numbers based on station number


In [4]:
lines_major = {'1': ('0.0','11.0'),
               '2': ('12.0','23.0'),
               '3': ('24.1', '24.311'),
               '4':  ('25.1', '25.23'),
               '5':  ('26.0', '28.0'),
               '6':   ('29.0','38.0'),
               '7':   ('39.0','51.0')}

lines_minor = {'3.1': ('24.1', '24.111'),
               '3.2': ('24.2', '24.211'),
               '3.3': ('24.3', '24.311'),
               '4.1': ('25.1', '25.11'),
               '4.2': ('25.202', '25.21'),
               '4.3': ('25.212', '25.22'),
               '4.4': ('25.222', '25.23')}

In [5]:
lut['line_V2'] = lut['line']
lut.head(3)


Out[5]:
line station feature_nr feat_nr_dat name_dat name_cat name_num col_dat col_num col_cat line_V2
station_V2
0.0 0 0 0 1.0 L0_S0_D1 NaN L0_S0_F0 0.0 0.0 NaN 0
0.0 0 0 2 3.0 L0_S0_D3 NaN L0_S0_F2 1.0 1.0 NaN 0
0.0 0 0 4 5.0 L0_S0_D5 NaN L0_S0_F4 2.0 2.0 NaN 0

In [6]:
for k,v in lines_major.iteritems():
    lut.loc[float(v[0]):float(v[1]),'line_V2'] = k
    
for k,v in lines_minor.iteritems():
    lut.loc[float(v[0]):float(v[1]),'line_V2'] = k

In [7]:
lut.reset_index(inplace=True)

In [8]:
# Move index to last
cols = [x for x in lut.columns if x[-2:]!='V2'] + ['station_V2','line_V2']

lut = lut[cols]

In [9]:
lut.head()


Out[9]:
line station feature_nr feat_nr_dat name_dat name_cat name_num col_dat col_num col_cat station_V2 line_V2
0 0 0 0 1.0 L0_S0_D1 NaN L0_S0_F0 0.0 0.0 NaN 0.0 1
1 0 0 2 3.0 L0_S0_D3 NaN L0_S0_F2 1.0 1.0 NaN 0.0 1
2 0 0 4 5.0 L0_S0_D5 NaN L0_S0_F4 2.0 2.0 NaN 0.0 1
3 0 0 6 7.0 L0_S0_D7 NaN L0_S0_F6 3.0 3.0 NaN 0.0 1
4 0 0 8 9.0 L0_S0_D9 NaN L0_S0_F8 4.0 4.0 NaN 0.0 1

Export


In [10]:
lut.to_csv(const.LOOK_UP_TABLE, index=False)