Skip to content

slugify allows dashes

Slugify allows dashes, but dashes are not valid python identifiers.

This is an issue in the following situation:

df = pd.DataFrame.from_dict({'A-1': [10,11], 'B': [100, 200] })
for row in df.itertuples():
    getattr(row, 'A-1')

Gives:

AttributeError: 'Pandas' object has no attribute 'A-1'

Solution: adapt the slugify function to disallow dashes and make it fit for use for sanitizing df-column names.