Skip to content

Instantly share code, notes, and snippets.

Created November 30, 2020 07:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
df.rename(columns={"User Rating": "User_Rating"}, inplace=True)
df[df.Author == 'J. K. Rowling']
df[df.Author == 'J.K. Rowling']
df.loc[df.Author == 'J. K. Rowling', 'Author'] = 'J.K. Rowling'
df['name_len'] = df['Name'].apply(lambda x: len(x) - x.count(" ")) # subtract whitespaces
punctuations = string.punctuation
print('list of punctuations : ', punctuations)
# percentage of punctuations
def count_punc(text):
"""This function counts the number of punctuations in a text"""
count = sum(1 for char in text if char in punctuations)
return round(count/(len(text) - text.count(" "))*100, 3)
# apply function
df['punc%'] = df['Name'].apply(lambda x: count_punc(x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment