<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Title
Step1:  Create Text Data
Step2:  Create Bag Of Words
Step3:  View Bag Of Words Matrix Column Headers
Step4:  View As A Data Frame
<ASSISTANT_TASK:>
Python Code:
# Load library
import numpy as np
from sklearn.feature_extraction.text import CountVectorizer
import pandas as pd
Explanation: Title: Bag Of Words
Slug: bag_of_words
Summary: How to encode unstructured text data as bags of words for machine learning in Python. 
Date: 2017-09-09 12:00
Category: Machine Learning
Tags: Preprocessing Text
Authors: Chris Albon
<a alt="Bag Of Words" href="https://machinelearningflashcards.com">
    <img src="bag_of_words/Bag_Of_Words_print.png" class="flashcard center-block">
</a>
Preliminaries
End of explanation
# Create text
text_data = np.array(['I love Brazil. Brazil!',
                      'Sweden is best',
                      'Germany beats both'])
Explanation: Create Text Data
End of explanation
# Create the bag of words feature matrix
count = CountVectorizer()
bag_of_words = count.fit_transform(text_data)
# Show feature matrix
bag_of_words.toarray()
Explanation: Create Bag Of Words
End of explanation
# Get feature names
feature_names = count.get_feature_names()
# View feature names
feature_names
Explanation: View Bag Of Words Matrix Column Headers
End of explanation
# Create data frame
pd.DataFrame(bag_of_words.toarray(), columns=feature_names)
Explanation: View As A Data Frame
End of explanation
<END_TASK>