This file contains 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
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