Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created November 30, 2020 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/b8be6517a9be30ccbe17f1a2003ed3b5 to your computer and use it in GitHub Desktop.
Save amankharwal/b8be6517a9be30ccbe17f1a2003ed3b5 to your computer and use it in GitHub Desktop.
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