Skip to content

Instantly share code, notes, and snippets.

@andrewmoles2
Created December 6, 2024 11:46
Show Gist options
  • Save andrewmoles2/1caedef434b2353ad4639527fb1ee75c to your computer and use it in GitHub Desktop.
Save andrewmoles2/1caedef434b2353ad4639527fb1ee75c to your computer and use it in GitHub Desktop.
Janitor clean names in Python
def clean_names(cols):
current_cols = cols
new_cols = []
for c in range(0, len(current_cols)):
new_cols.append(
current_cols[c].lower().replace(' ', '_').replace('(', '').replace(')', '')
)
return(new_cols)
# we use the .columns method to access the column names
# this applies to both polars and pandas
#df.columns = clean_names(df.columns)
#print(df.head())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment