zoukankan      html  css  js  c++  java
  • python plot生成水平条线图

    #!/usr/local/bin/python
    # -*- coding:utf-8 -*-
    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='C:UsersTLCBDesktopdata_analyzech02usagov_bitly_data2012-03-16-1331923249.txt'
    print path
    a= open(path)
    print type(a)
    print dir(a)
    print a.readline()
    records=[]
    for line in open(path):
        #print json.loads(line)
        records.append(json.loads(line))
    print '--------------------------------'
    records = records[:10]
    print records
    frame=DataFrame(records)
    print '####################################'
    print frame['tz']
    print frame['tz'].value_counts()
    print '####################################'
    clean_tz = frame['tz'].fillna('Missing')
    clean_tz[clean_tz =='']='Unknown'
    tz_counts = clean_tz.value_counts()
    print tz_counts[:10]
    tz_counts[:10].plot(kind='barh',rot=0)
    
    print plt.show()
    
    
    
    
    
    
    
    
  • 相关阅读:
    python-字典
    python-列表
    python:基础数据类型
    前端之JS
    数据库之备份,恢复
    前端之CSS
    前端之CSS笔记
    前端之html
    数据库之操作使用python操作mysql数据库
    何为javaBean?
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348691.html
Copyright © 2011-2022 走看看