Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created Nov 30, 2020
Embed
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