Skip to content

Commit

Permalink
need to reset index and drop index name if exists in col of dataframe
Browse files Browse the repository at this point in the history
  • Loading branch information
kuanb committed Apr 20, 2017
1 parent e308e1a commit 69c7e8c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions urbanaccess/gtfs/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,14 @@ def interpolatestoptimes(stop_times_df, calendar_selected_trips_df, day):
df_for_interpolation['stop_sequence_merge'] = (
df_for_interpolation[~trailing]['stop_sequence'])

# Need to check if existing index in column names and drop if so (else
# a ValueError where Pandas can't insert b/c col already exists will occur)
drop_bool = False
if _check_if_index_name_in_cols(df_for_interpolation):
drop_bool = True
df_for_interpolation.reset_index(inplace=True, drop=drop_bool)

# Merge back into original index
df_for_interpolation.reset_index(inplace=True)
interpolated_df = pd.merge(df_for_interpolation, melted, 'left',
on=['stop_sequence_merge', 'unique_trip_id'])
interpolated_df.set_index('index', inplace=True)
Expand Down Expand Up @@ -763,4 +769,10 @@ def load_processed_gtfs_data(dir=config.settings.data_folder,filename=None):
if 'calendar_dates' in store.keys():
gtfsfeeds_df.calendar_dates = hdf5_to_df(dir=dir,filename=filename,key='calendar_dates')

return gtfsfeeds_df
return gtfsfeeds_df

# helper functions
def _check_if_index_name_in_cols(df):
cols = df.columns.values
iname = df.index.name
return (iname in cols)

0 comments on commit 69c7e8c

Please sign in to comment.