def apply_bq_naming_requirements(dataframe: pd.DataFrame) -> pd.DataFrame:
"""
Removes accents.
Replaces spaces and `-` with `_`.
Lowercase.
Args:
dataframe: Dataframe to be formatted.
Returns:
Pandas dataframe with columns changed.
"""
def strip_accents(s):
return ''.join(c for c in unicodedata.normalize('NFD', s)
if unicodedata.category(c) != 'Mn')
fixed_columns = [column.replace("-", "_") for column in dataframe.columns.tolist()]
fixed_columns = [column.replace(" ", "_") for column in fixed_columns]
fixed_columns = [strip_accents(column) for column in fixed_columns]
fixed_columns = [column.lower() for column in fixed_columns]
dataframe.columns = fixed_columns
return dataframe
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter