We can create a Dask Bag using a text file by using the read_text() method, as follows:
# Import dask bag
import dask.bag as db
# Create a bag of text file
text = db.read_text('sample.txt')
# Show initial 2 items from text
text.take(2)
This results in the following output:
('Hi! how are you? \n', '\n')
In the preceding code, we read a text file into a dask bag object by using the read_text() method. This allowed us to show the two initial items in the Dask Bag.