昨天发完帖子后,有同学问出图是用的哪个库,现在把出图的代码贴上,用的是pyecharts。
上一篇帖子 使用python爬取数据并分析2018北京积分落户情况
#-*-coding:utf-8-*-
import time
import MySQLdb
import sys
from pandas import DataFrame
from pyecharts import Bar,Pie,Page
defaultencoding = 'utf-8'
if sys.getdefaultencoding() != defaultencoding:
reload(sys)
sys.setdefaultencoding(defaultencoding)
db = MySQLdb.connect("localhost", "root", "root", "py", charset='utf8' )
cursor = db.cursor()
def get_privince_count(dataframe):
indexs = []
counts = []
for index in dataframe.index:
indexs.append(index)
counts.append(dataframe[index])
print counts
print indexs
page = Page()
labels = [indexs]
sizes = [counts]
attr = indexs
v1 = counts
bar =Bar("积分落户年龄统计图" )
bar.add("地区分布",attr,v1,is_stack=True,is_label_show=True,is_datazoom_show =True,
is_random = True)
page.add(bar)
bar.show_config()
bar.render()
sql = "select name,score,city,unit,year from bjrbj"
cursor.execute(sql)
results = cursor.fetchall()
data = list(results)
data = [list(i) for i in data]
df = DataFrame(data, columns=["name","score","city","unit","year"])
score = df['year']
score = score.value_counts()[:10]
get_privince_count(score)
免费的评分可以给点儿吗??? |