Created
October 14, 2021 08:20
-
-
Save RaMSFT/40365e33a9e1465787ffb9437839d1be to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| ## Import Pandas to make dataframe | |
| import pandas as pd | |
| ## Import Regular Expression - Used to replace all special characters other than alphanumeric | |
| import re | |
| ## Import Counter from collections | |
| from datetime import datetime | |
| ## Input | |
| giventext = "This is Medium article presented by ramstkp in the month of October. On the day of writing it was cold, and autumn started early this in the october month. October month is relatively less cold compared to winter months" | |
| ## Replacing all other characters other than alphanumerics | |
| giventext = re.sub('[^a-zA-Z0-9 \n]', '', giventext) | |
| ## Converting to lower and splitting the text to list by word (split by space) | |
| text_to_list = giventext.lower().split() | |
| ## Create dataframe and group by "word" and get largest 10 words with count | |
| df = pd.DataFrame(text_to_list, columns=['word']).groupby("word")['word'].count().nlargest(10) | |
| print(df) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment