Let's store a Dask Bag in a DataFrame:
# Import dask bag
import dask.bag as db
# Create a bag of dictionary items
dict_bag = db.from_sequence([{'item_name': 'Egg', 'price': 5},
{'item_name': 'Bread', 'price': 20},
{'item_name': 'Milk', 'price': 54}],
npartitions=2)
# Convert bag object into dataframe
df = dict_bag.to_dataframe()
# Execute the graph results
df.compute()
This results in the following output:
In the preceding example, we created a Dask Bag of dictionary items and converted it into a Dask DataFrame using the to_dataframe() method. In the next section, we'll look at Dask Delayed.