- Python Data Science - Matplotlib
- Python Data Science - SciPy
- Python Data Science - Numpy
- Python Data Science - Pandas
- Python Data Science - Environment Setup
- Python Data Science - Getting Started
- Python Data Science - Home
Python Data Processing
- Python Stemming and Lemmatization
- Python word tokenization
- Python Processing Unstructured Data
- Python Reading HTML Pages
- Python Data Aggregation
- Python Data Wrangling
- Python Date and Time
- Python NoSQL Databases
- Python Relational databases
- Python Processing XLS Data
- Python Processing JSON Data
- Python Processing CSV Data
- Python Data cleansing
- Python Data Operations
Python Data Visualization
- Python Graph Data
- Python Geographical Data
- Python Time Series
- Python 3D Charts
- Python Bubble Charts
- Python Scatter Plots
- Python Heat Maps
- Python Box Plots
- Python Chart Styling
- Python Chart Properties
Statistical Data Analysis
- Python Linear Regression
- Python Chi-square Test
- Python Correlation
- Python P-Value
- Python Bernoulli Distribution
- Python Poisson Distribution
- Python Binomial Distribution
- Python Normal Distribution
- Python Measuring Variance
- Python Measuring Central Tendency
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Python - Word Tokenization
Word tokenization is the process of spptting a large sample of text into words. This is a requirement in natural language processing tasks where each word needs to be captured and subjected to further analysis pke classifying and counting them for a particular sentiment etc. The Natural Language Tool kit(NLTK) is a pbrary used to achieve this. Install NLTK before proceeding with the python program for word tokenization.
conda install -c anaconda nltk
Next we use the word_tokenize method to sppt the paragraph into inspanidual words.
import nltk word_data = "It originated from the idea that there are readers who prefer learning new skills from the comforts of their drawing rooms" nltk_tokens = nltk.word_tokenize(word_data) print (nltk_tokens)
When we execute the above code, it produces the following result.
[ It , originated , from , the , idea , that , there , are , readers , who , prefer , learning , new , skills , from , the , comforts , of , their , drawing , rooms ]
Tokenizing Sentences
We can also tokenize the sentences in a paragraph pke we tokenized the words. We use the method sent_tokenize to achieve this. Below is an example.
import nltk sentence_data = "Sun rises in the east. Sun sets in the west." nltk_tokens = nltk.sent_tokenize(sentence_data) print (nltk_tokens)
When we execute the above code, it produces the following result.
[ Sun rises in the east. , Sun sets in the west. ]Advertisements