Skip to content

Commit c08a985

Browse files
committed
Sort and rename columns
1 parent 58988ff commit c08a985

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

tools/combine_crosswalk_tables.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def combine_crosswalk_tables(data_directory, output_filename):
2222
filename, usecols=['HUC', 'HydroID', 'feature_id', 'LakeID'], dtype={'HUC': str}
2323
)
2424
file_df = file_df.drop_duplicates()
25-
file_df = file_df.rename(columns={'HUC': 'huc8'})
2625
file_df['BranchID'] = os.path.split(os.path.dirname(filename))[1]
2726

2827
dfs.append(file_df)
@@ -31,9 +30,18 @@ def combine_crosswalk_tables(data_directory, output_filename):
3130

3231
if len(dfs) > 1:
3332
df = pd.concat(dfs)
33+
34+
df = df.rename(
35+
columns={'HUC': 'huc8', 'HydroID': 'hydro_id', 'LakeID': 'lake_id', 'BranchID': 'branch_id'}
36+
)
37+
38+
df = df.sort_values(by=['feature_id', 'huc8', 'branch_id', 'hydro_id'])
39+
3440
df = df.reset_index(drop=True)
3541
df['hand_id'] = df.index + 1
3642

43+
df = df[['hand_id', 'feature_id', 'huc8', 'branch_id', 'hydro_id', 'lake_id']]
44+
3745
df.to_csv(output_filename, index=False)
3846

3947

0 commit comments

Comments
 (0)