Skip to content

Instantly share code, notes, and snippets.

@szeitlin
Created December 2, 2014 00:45
Show Gist options
  • Select an option

  • Save szeitlin/5e55bec69e88a3a73bd4 to your computer and use it in GitHub Desktop.

Select an option

Save szeitlin/5e55bec69e88a3a73bd4 to your computer and use it in GitHub Desktop.
remove symbols from strings (helper function for data cleaning)
def remove_symbols(name):
""" Remove symbols from string and return as one word.
Replace '&' with '_and_'
Replace '/' with '_or_'
Remove spaces
Replace '(' with _
Remove ')'
(str) -> (str)
>>>remove_symbols("Plug & Perf")
Plug_and_Perf
>>>remove_symbols("CT Cut/Port (Packer)")
CTCut_or_Port_Packer
"""
symbol_dict = {'&':'_and_', '/':"_or_", '(': '_'}
parsable = ''
for char in name:
if char in symbol_dict:
parsable +=symbol_dict[char]
elif char == ')':
parsable += ' '
else:
parsable += char
nname = remove_spaces(str(parsable))
return nname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment