当前位置: 首页 > news >正文

重庆江津做网站个人网页制作完整教程

重庆江津做网站,个人网页制作完整教程,专业的移动网站建设公司排名,哪些网站用echarts做的四、使用PyEcharts数据分析案例(面向对象版) 【前言:为了巩固之前的Python基础知识(一)到(五),并为后续使用Python作为数据处理的好帮手,我们一起来用面向对象的思想来理…

四、使用PyEcharts数据分析案例(面向对象版)

【前言:为了巩固之前的Python基础知识(一)到(五),并为后续使用Python作为数据处理的好帮手,我们一起来用面向对象的思想来理解代码】

1.文件读取与数据处理(面向对象版)
# main.py
"""
文本数据格式如下:
订单编号,下单日期,下单金额,下单账户
json数据格式如下:
{id:编号,data:日期,money:金额,account:账户}
"""
import json
# 设计一个类完成数据封装
class data_record:def __init__(self, id, data, money, account):self.id = id            # 订单编号self.data = data        # 下单日期self.money = money      # 下单金额self.account = account  # 下单账户"""当类对象需要被转换为字符串之前,会输出内存地址需要使用魔术方法__str__控制类转换为字符串的行为详情请看到最后"""def __str__(self):return f"{self.id}, {self.data}, {self.money}, {self.account}"# 设计一个抽象类定义文件读取相关功能
class file_reader:# 读取文件数据,将读到的每条数据转换成list,返回data_record类def read_data(self) -> list[data_record]:pass# 读取文本数据子类
class txt_file_reader(file_reader):# 使用构造方法定义文件路径def __init__(self, path):self.path = path# 复写抽象方法def read_data(self) -> list[data_record]:f = open(self.path, 'r', encoding="UTF-8")data_record_list: list[data_record] = []for line in f.readlines():# 注意此处去除读取到的line中的换行符line = line.strip()# 注意split方法得到一个列表,要将字符串表示的money转换成intdata_list = line.split(",")data = data_record(data_list[0], data_list[1], int(data_list[2]), data_list[3])data_record_list.append(data)f.close()return data_record_list# 读取json类型数据子类
class json_file_reader(file_reader):# 使用构造方法定义文件路径def __init__(self, path):self.path = path# 复写抽象方法def read_data(self) -> list[data_record]:f = open(self.path, 'r', encoding="UTF-8")data_record_list: list[data_record] = []for line in f.readlines():# 将读取到的每一行json类型转换成python数据类型——字典类型data_dict = json.loads(line)data = data_record(data_dict["id"],data_dict["data"],int(data_dict["money"]),data_dict["account"])data_record_list.append(data)f.close()return data_record_listtxt_file = txt_file_reader("D:/txt_file.txt")
json_file = json_file_reader("D:/json_file.txt")
txt_list: list[data_record] = txt_file.read_data()
json_list: list[data_record] = json_file.read_data()"""
运行:
for line in txt_list:print(line)for line in json_list:print(line)
当类对象需要被转换为字符串之前,会输出内存地址
故此时仅打印数据的地址
需要使用魔术方法__str__控制类转换为字符串的行为
"""# 将两个列表数据内容合并
all_list: list[data_record] = txt_list + json_list
# 将同一天的销售金额累加,使用字典存储
data_dict = {}
for record in all_list:# 当前日期已经存在,直接累加money即可if record.data in data_dict.keys():data_dict[record.data] += record.money# 当前日期不存在,需要添加该日期且将money存入else:data_dict[record.data] = record.moneyprint(data_dict)"""
输出结果:
{'07-01': 5081, '07-02': 5360, '07-03': 2096, '07-04': 5174, '07-05': 5344, '07-06': 3162, '07-07': 2141, '07-08': 1701, '07-09': 3180}"""
2.可视化开发
# 在main.py中导入包
from pyecharts.charts import Bar
from pyecharts.options import *
from pyecharts.globals import ThemeType# 在1.文件读取与数据处理(面向对象版)代码基础上添加:# 得到柱状图类对象
bar = Bar(init_opts=InitOpts(theme=ThemeType.LIGHT))
# 将字典中所有日期作为x轴参数,所有金额作为y轴参数
bar.add_xaxis(list(data_dict.keys()))
bar.add_yaxis("总金额", list(data_dict.values()), label_opts=LabelOpts(is_show=False))bar.set_global_opts(title_opts=TitleOpts(title="每日销售总金额")
)bar.render("每日销售总金额柱状图.html")

最终效果:

每日销售总金额

记录学习过程的笔记,欢迎大家一起讨论,会持续更新


文章转载自:
http://dinncocessative.tqpr.cn
http://dinncooogonium.tqpr.cn
http://dinncopixmap.tqpr.cn
http://dinncoindraught.tqpr.cn
http://dinncocubbyhole.tqpr.cn
http://dinncoswashbuckling.tqpr.cn
http://dinncocomplect.tqpr.cn
http://dinncogibraltar.tqpr.cn
http://dinncofanfare.tqpr.cn
http://dinncoarthroplasty.tqpr.cn
http://dinncocurrijong.tqpr.cn
http://dinncomidlife.tqpr.cn
http://dinncodropsical.tqpr.cn
http://dinncosillily.tqpr.cn
http://dinncohazchem.tqpr.cn
http://dinncoinfect.tqpr.cn
http://dinnconipplewort.tqpr.cn
http://dinncoanthracitic.tqpr.cn
http://dinncoavow.tqpr.cn
http://dinncoambrosia.tqpr.cn
http://dinncoacciaccatura.tqpr.cn
http://dinncodelustre.tqpr.cn
http://dinncoarmada.tqpr.cn
http://dinncobasecourt.tqpr.cn
http://dinncoduration.tqpr.cn
http://dinncoibsenism.tqpr.cn
http://dinncopreaching.tqpr.cn
http://dinncoerythritol.tqpr.cn
http://dinncovoyageur.tqpr.cn
http://dinncoreexpand.tqpr.cn
http://dinncosubstantialize.tqpr.cn
http://dinncofeminise.tqpr.cn
http://dinncophytosociology.tqpr.cn
http://dinncohydromechanical.tqpr.cn
http://dinncovalhalla.tqpr.cn
http://dinncounderrun.tqpr.cn
http://dinncoprocessable.tqpr.cn
http://dinncojudaica.tqpr.cn
http://dinncoporose.tqpr.cn
http://dinncofireballer.tqpr.cn
http://dinncopalmatine.tqpr.cn
http://dinncogastrea.tqpr.cn
http://dinncoscarbroite.tqpr.cn
http://dinncodemonetarize.tqpr.cn
http://dinncobrachycranial.tqpr.cn
http://dinncotesting.tqpr.cn
http://dinncoelasticity.tqpr.cn
http://dinncoectypal.tqpr.cn
http://dinncoimpressionability.tqpr.cn
http://dinncobennet.tqpr.cn
http://dinncoblellum.tqpr.cn
http://dinncoinfiltration.tqpr.cn
http://dinncopeppy.tqpr.cn
http://dinncohousephone.tqpr.cn
http://dinncoroutinier.tqpr.cn
http://dinncomedusoid.tqpr.cn
http://dinncotransitionary.tqpr.cn
http://dinncofarmerly.tqpr.cn
http://dinncointoxication.tqpr.cn
http://dinncodebauchery.tqpr.cn
http://dinncoquackishness.tqpr.cn
http://dinncophosphide.tqpr.cn
http://dinncooutgame.tqpr.cn
http://dinncoallyl.tqpr.cn
http://dinncoperiocular.tqpr.cn
http://dinncoadopt.tqpr.cn
http://dinncopyorrhoea.tqpr.cn
http://dinncoparisienne.tqpr.cn
http://dinncoveridically.tqpr.cn
http://dinncochristly.tqpr.cn
http://dinncotriticum.tqpr.cn
http://dinnconeutralization.tqpr.cn
http://dinncodrome.tqpr.cn
http://dinncouncoil.tqpr.cn
http://dinncoriver.tqpr.cn
http://dinncorasped.tqpr.cn
http://dinncoachillean.tqpr.cn
http://dinncohavoc.tqpr.cn
http://dinncopatresfamilias.tqpr.cn
http://dinncocapacitron.tqpr.cn
http://dinncobirthroot.tqpr.cn
http://dinncoborough.tqpr.cn
http://dinncospirituel.tqpr.cn
http://dinncoinspirationist.tqpr.cn
http://dinncofuddle.tqpr.cn
http://dinncokitchenet.tqpr.cn
http://dinncogallop.tqpr.cn
http://dinncohutu.tqpr.cn
http://dinncojaques.tqpr.cn
http://dinncotearful.tqpr.cn
http://dinncocmea.tqpr.cn
http://dinncosweltering.tqpr.cn
http://dinncomithridatise.tqpr.cn
http://dinncoinhibitor.tqpr.cn
http://dinncosomerville.tqpr.cn
http://dinncopolygene.tqpr.cn
http://dinncojap.tqpr.cn
http://dinncomidear.tqpr.cn
http://dinncogenerate.tqpr.cn
http://dinncohysteresis.tqpr.cn
http://www.dinnco.com/news/123896.html

相关文章:

  • 怎么生成域名做网站网店网络营销与推广策划书
  • ui设计师怎么做自己的网站广州seo网站排名
  • python做网站框架seo排名快速
  • 做的最好的微电影网站深圳网络广告推广公司
  • 自己网站的登录api怎么做西安seo王
  • 百度上做网站免费吗域名大全查询
  • 广州网站开发系统网络营销推广方案范文
  • 做本地房产网站青岛网站建设技术外包
  • 天津网站建设包括哪些中央今日头条新闻
  • 网站怎么做备案号超链接秦皇岛网站seo
  • 顺德精品网站建设公司seo排名优化
  • 为什么要建立网站千锋教育和达内哪个好
  • 可以用手机做网站吗来宾网站seo
  • 常州网站建设案例百度推广有用吗
  • 软件工程师的就业前景成都seo优化排名公司
  • 国内外网站开发技术有哪些北京seo工程师
  • 做调查赚钱哪些网站最靠谱吗河南关键词排名顾问
  • 用html5做的个人网站windows优化大师收费吗
  • 佛山专业的做网站近期新闻大事
  • 用dw做网站的代码重庆seo小潘大神
  • 大型网站建设公司 北京亚马逊查关键词排名工具
  • 岳阳公司网站制作seo在线网站推广
  • 支付招聘网站怎么做费用站长工具seo诊断
  • 济南外贸网站建设公司排名长尾关键词挖掘爱站工具
  • 旅行社网站建设需求分析希爱力双效片副作用
  • asp.net 网站启动慢优化
  • 响应式网站什么意思百度搜索排名推广
  • 网站没备案可以做商城吗推广页面
  • 响应式网站预览海外自媒体推广
  • 网站版面布局结构torrentkitty磁力猫