I am a Quantitative Analyst/Developer and Data Scientist with backgroud of Finance, Education, and IT industry. This site contains some exercises, projects, and studies that I have worked on. If you have any questions, feel free to contact me at ih138 at columbia dot edu.
Delete all characters from s that are in deletechars, then translate the characters using table, which must be a 256-character string giving the translation for each character value, indexed by its ordinal. If table is None, then only the character deletion step is performed.
Return a translation table for passing to translate(), that will map each character in from into the character at the same position in to; from and to must have the same length.
Example 1:
import string
table1 = string.maketrans('xyz', 'abc')
sample = "x and y and z can be abc."
sample.translate(table1)
output:
a and b and c can be abc.
Example 2:
import string
def removePunct(text):
tbl = string.maketrans("","")
out = text.translate(tbl, string.punctuation)
out = out.strip()
out = out.lower()
return out
Example 3:
Split Strings
words = "fast toward; lime, flow.engine, for"
import re
re.split(r'[;,\s]\s*', words)
output
['fast', 'toward', 'lime', 'flow', 'engine', 'for']
##
References:
[1] Cuesta, Hector. Practical Data Analysis: Transform, Model, and Visualize Your Data through Hands-on Projects, Developed in Open Source Tools. Birmingham, UK: Packt, 2013. Print.
[2] Perkins, Jacob. Python Text Processing with NTLK 2.0 Cookbook: Over 80 Practical Recipes for Using Python’s NLTK Suite of Libraries to Maximize Your Natural Language Processing Capabilities. Birmingham: PACKT, 2010. Print.
[3] Bird, Steven, Ewan Klein, and Edward Loper. Natural Language Processing with Python. Beijing: O’Reilly, 2009. Print.
[4] Russel, Matthew A. Mining the Social Web: Data Mining Facebook, Twitter, Linkedin, Google , Github, and More. Sebastopol, CA: O’Reilly, 2014. Print.