Created
December 2, 2014 00:45
-
-
Save szeitlin/5e55bec69e88a3a73bd4 to your computer and use it in GitHub Desktop.
remove symbols from strings (helper function for data cleaning)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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