from pandas import DataFrame,Series
import pandas as pd
import numpy as np
import sys
import matplotlib.pyplot as plt
reload(sys)
sys.setdefaultencoding('utf8')
import json
import time
path='E:\ch02\usagov_bitly_data2012-03-16-1331923249.txt'
a= open(path).readlines()
# print a
print type(a)
arr01=[]
for x in a:
#print x
# print type(x)
y=json.loads(x)
#print y
# time.sleep(100)
for z in y:
arr01.append(y[z])
print '--------------------------------'
print arr01
records=[json.loads(line) for line in open(path)]
print records
frame=DataFrame(records)
print frame
print frame['tz'][:10]
print frame['tz'].value_counts()[:10]
clean_tz=frame['tz'].fillna('Missing')
clean_tz[clean_tz == ''] ='Unknown'
print '-----------------------------------------'
print clean_tz.value_counts()[:10]
print clean_tz.value_counts()[:10].plot(kind='barh',rot=0)
print plt.show()