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
In [2]:
lut = pd.read_csv(const.LOOK_UP_TABLE)
lut.set_index('station_V2', inplace=True)
lut.head(3)
Out[2]:
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]:
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]:
In [10]:
lut.to_csv(const.LOOK_UP_TABLE, index=False)