@@ -84,8 +84,6 @@ def _check_row_spans(dat):
8484 dat0 [['ELR' , 'Mileage' ]] = dat0 [['ELR' , 'Mileage' ]].map (lambda x : x .split (' &&& ' ))
8585 dat0 = dat0 .explode (['ELR' , 'Mileage' ], ignore_index = True )
8686
87- dat0 .sort_values (['Station' ], ignore_index = True , inplace = True )
88-
8987 return dat0
9088
9189
@@ -122,22 +120,28 @@ def _parse_station_column(dat):
122120 x = 'Heathrow Junction [sometimes referred to as Heathrow Interchange]\t \t / [no CRS?]'
123121 """
124122
125- temp1 = dat ['Station' ].str .split ('\t \t ' , n = 1 , expand = True )
126- temp1 .columns = ['Station' , 'CRS' ]
127- dat ['Station' ] = temp1 ['Station' ].str .rstrip (' / ' ).str .strip ()
123+ stn_col_name = [col for col in dat .columns if 'Station' in col ][0 ]
124+ temp1 = dat [stn_col_name ].str .split ('\t \t ' , n = 1 , expand = True )
125+
126+ if stn_col_name != 'Station' :
127+ dat .rename (columns = {stn_col_name : 'Station' }, inplace = True )
128+ stn_col_name = 'Station'
129+
130+ temp1 .columns = [stn_col_name , 'CRS' ]
131+ dat [stn_col_name ] = temp1 [stn_col_name ].str .rstrip (' / ' ).str .strip ()
128132
129133 # Get notes for stations
130134 stn_note_ = pd .Series ('' , index = dat .index )
131- for i , x in enumerate (temp1 ['Station' ]):
135+ for i , x in enumerate (temp1 [stn_col_name ]):
132136 if '[' in x and ']' in x :
133137 y = re .search (r' \[(.*)](✖.*)?' , x ).group (0 ) # Station Note
134- dat .loc [i , 'Station' ] = x .replace (y , '' ).strip ()
138+ dat .loc [i , stn_col_name ] = str ( x ) .replace (y , '' ).strip ()
135139 if '✖' in y :
136140 stn_note_ [i ] = '; ' .join ([y_ .strip (' []' ) for y_ in y .split ('✖' )])
137141 else :
138142 stn_note_ [i ] = y .strip (' []' )
139143
140- dat .insert (loc = dat .columns .get_loc ('Station' ) + 1 , column = 'Station Note' , value = stn_note_ )
144+ dat .insert (loc = dat .columns .get_loc (stn_col_name ) + 1 , column = 'Station Note' , value = stn_note_ )
141145
142146 temp2 = temp1 ['CRS' ].str .replace (' / /' , ' &&& ' ).str .split (
143147 r' | / ' , regex = True , expand = True ).fillna ('' )
@@ -154,7 +158,7 @@ def _parse_station_column(dat):
154158 lambda z : ' and ' .join (['{} [{}]' .format (* z_ .split ('✖' )) for z_ in z .split (' &&& ' )])
155159 if ' &&& ' in z else z ).str .strip ()
156160
157- dat = pd .concat ([dat , temp2 ], axis = 1 )
161+ dat = pd .concat ([dat , temp2 ], axis = 1 ). sort_values ( stn_col_name )
158162
159163 return dat
160164
0 commit comments