pydit.wrangling.cleanup_dataframe_columns_names.cleanup_column_names¶
- pydit.wrangling.cleanup_dataframe_columns_names.cleanup_column_names(obj, max_field_name_len=40, silent=False)[source]¶
Cleanup the column names of a Pandas dataframe.
e.g. removes non alphanumeric chars, replaces _ instead of space, perc instead of %, converts main currency signs (usd, gpb, eur), strips trailing spaces, converts to lowercase.
It also ensures that the resulting list doesn’t have duplicates or nulls, in which case it would fix.
- Parameters:
obj (pandas.DataFrame or list of strings or string) – The dataframe or a list of strings, or a string to clean up.
max_field_name_len (int, optional, default 40) – The maximum length of the field name
- Returns:
pandas.DataFrame – A copy of the pandas DataFrame with cleaned column names
list – A copy of the list of strings with cleaned column names if the input was a list
str – A cleaned string if the input was a sole string. Note that if you provided a single element list it will still return a list of one element.