python 数据可视化
作者:互联网
数据可视化
# -*- coding:utf-8 -*- # 异常值处理 import pandas as pda import numpy as npy import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as pyl import io 数据可视化 # 评论数异常>100000,价格异常>1000 line = len(data.values) col = len(data.values[0]) da = data.values for i in range(0, line): for j in range(0, col): if (int(da[i][2]) > 1000): # print(da[i]) da[i][2] = data["价格"].mean() if (int(da[i][3]) > 100000): # print(da[i]) da[i][3] = data["评论"].mean() daF = pda.DataFrame(da) daF.sort_values(by=3) da2 = da.T price = da2[2] comt = da2[3] fig2 = pyl.figure() pyl.plot(price, comt, 'o') canvas = fig2.canvas buffer = io.BytesIO() canvas.print_png(buffer) img_spl2 = buffer.getvalue() # print(data)s buffer.close() output['img_第二张散点图'] = img_spl2 def index(data): # 输出结果必须为字典output output = {} data = pda.DataFrame(data[1:], columns=data[0]) # print(data) data.describe() # 画散点图(横轴为价格,纵轴为评论数) # 得到价格 data2 = data.T price = data2.values[2] # 得到评论数据 fig = pyl.figure() # print(price) # print(comt) pyl.plot(price, comt, 'o') canvas = fig.canvas buffer = io.BytesIO() canvas.print_png(buffer) img_spl = buffer.getvalue() # print(data)s buffer.close() output['img_第二张散点图'] = img_spl2 def index(data): # 输出结果必须为字典output output = {} data = pda.DataFrame(data[1:], columns=data[0]) # print(data) data.describe() # 画散点图(横轴为价格,纵轴为评论数) # 得到价格 data2 = data.T price = data2.values[2] # 得到评论数据 comt = data2.values[3] fig = pyl.figure() # print(price) pyl.plot(price, comt, 'o') canvas = fig.canvas buffer = io.BytesIO() canvas.print_png(buffer) img_spl = buffer.getvalue() # print(data)s buffer.close() output['img_散点图'] = img_spl # pyl.show() # pyl.show() # 分布分析--直方图 fre_price = dict() for num in da2[2]: fre_price[num] = fre_price.get(num, 0) + 1 fre_price.keys() fre_price.values() pyl.bar(list(fre_price.keys()), list(fre_price.values())) print(output) return output output['img_散点图'] = img_spl # pyl.show() # pyl.show() # 分布分析--直方图 fre_price = dict() for num in da2[2]: fre_price[num] = fre_price.get(num, 0) + 1 fre_price.keys() fre_price.values() pyl.bar(list(fre_price.keys()), list(fre_price.values())) print(output) return output
标签:fre,python,data,price,buffer,可视化,print,pyl,数据 来源: https://www.cnblogs.com/wei23/p/10890685.html