<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Additional Exercises for 02.27
Step1:  Since the number of children literaturs is a lot to analyze, we'll just randomly select 5 books to do a sentiment analysis using the dictionary method.
Note
Step2:  Question 2
Since these literatures are written for children, the overall sentiment rating is probably positive.
Question 3
<ASSISTANT_TASK:>
Python Code:
import pandas as pd
import nltk
import string
import matplotlib.pyplot as plt
#read in our data
df = pd.read_csv("../Data/childrens_lit.csv.bz2", sep = '\t', encoding = 'utf-8', compression = 'bz2', index_col=0)
df = df.dropna(subset=["text"])
df
Explanation: Additional Exercises for 02.27: Dictionary Method
Ex. 
Read in the childrens_lit.csv.bz2 file from the data folder.
Come up with a hypothesis on what you think the sentiment ratings is for children's literature.
Do a sentiment analysis on a subset of chilren's literature using the dictionary method from lecture.
Use the positive and negative words from lecture
Question 1
End of explanation
import numpy as np
np.random.seed(1)
df = df.sample(5)
df
Explanation: Since the number of children literaturs is a lot to analyze, we'll just randomly select 5 books to do a sentiment analysis using the dictionary method.
Note: In case you're not familiar with seed. Seed is just a function that initializes a fixed state for random number generatoring. Basically if everyone uses the same number as an input to seed(), then everyone will get the same result when generating randomly.
End of explanation
# Your code here
df['text_lc'] = df['text'].str.lower()
df['text_split'] = df['text_lc'].apply(nltk.word_tokenize)
df['text_split_clean'] = df['text_split'].apply(lambda x : [word for word in x if word not in string.punctuation])
df
df['text_length'] = df['text_split_clean'].apply(len)
df
# Your code here
pos_sent = open("../Data/positive_words.txt", encoding='utf-8').read()
neg_sent = open("../Data/negative_words.txt", encoding='utf-8').read()
positive_words = pos_sent.split('\n')
negative_words = neg_sent.split('\n')
df['num_pos_words'] = df['text_split_clean'].apply(lambda x: len([word for word in x if word in positive_words]))
df['num_neg_words'] = df['text_split_clean'].apply(lambda x: len([word for word in x if word in negative_words]))
df
df['prop_pos_words'] = df['num_pos_words']/df['text_length']
df['prop_neg_words'] = df['num_neg_words']/df['text_length']
df
Explanation: Question 2
Since these literatures are written for children, the overall sentiment rating is probably positive.
Question 3
End of explanation
<END_TASK>