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

做网站技术选择个人运营app需要多少钱

做网站技术选择,个人运营app需要多少钱,wordpress wp user,网页版传奇下载爬取基金收盘价并用pyecharts进行展现 一、用到的第三方包 因为使用到了一些第三方的包,包还是比较大的如果直接从社区下载比较费劲,所以建议配置国内镜像源,这里以清华的镜像源为例。 pip config set global.index-url https://pypi.tuna…

爬取基金收盘价并用pyecharts进行展现

一、用到的第三方包

因为使用到了一些第三方的包,包还是比较大的如果直接从社区下载比较费劲,所以建议配置国内镜像源,这里以清华的镜像源为例。

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config set global.trusted_host pypi.tuna.tsinghua.edu.cn

安装第三方包

pip install pandas bs4 pyecharts

二、数据获取

从网页爬取数据

import requests
from bs4 import BeautifulSoup
# 从url获取信息
response = requests.get('url地址')
# 解析HTML内容
soup = BeautifulSoup(response.text, 'html.parser')
soup.get_text()

1、从网页爬取每日最新数据

2、将数据追加存储到excel

# !/usr/bin/python
# -*-coding:utf-8 -*-
"""File        : spider.pyTime        : 2024/1/17 10:00Author      : 天选之子Email       : version     : python 3.10.11Description : 
"""
import datetime
import osimport numpy
import requests
from bs4 import BeautifulSoup
import pandasurl = "https://qt.gtimg.cn"
fund_code_list = ['sh510300', 'sz159995']
target_path = r'excel存储位置'
sheet_name = '存储的excel的sheet页'def get_fund_close_price(url_str):"""获取基金收盘价"""response = requests.get(url_str)soup = BeautifulSoup(response.text, 'html.parser')if soup is None:return '没找到'else:market = soup.get_text()return market.split('~')[4]def df_combiner(targetpath, dataframe, sheetname):"""将来源excel合并到目标excel:param targetpath::param dataframe::param sheetname::return: dataframe合并后的最终excel对象"""if not os.path.exists(targetpath):return Nonetar_data_frame = pandas.DataFrame(pandas.read_excel(targetpath, sheet_name=sheetname, keep_default_na=False))tar_date = set(numpy.array(tar_data_frame['日期']).tolist())to_date = set(numpy.array(dataframe['日期']).tolist())if to_date.issubset(tar_date):tar_df_all = tar_data_frameelse:if tar_data_frame is None:return dataframetar_df_all = pandas.concat([tar_data_frame, dataframe], ignore_index=True)return tar_df_alldef main():df_all = Nonefor fund_code in fund_code_list:fund_url = f'{url}/?q={fund_code}'result = get_fund_close_price(fund_url)print("该只基金的收盘价为:", result)print(datetime.datetime.now().strftime('%Y-%m-%d'))# 创建一个DataFramedata = {'日期': [datetime.datetime.now().strftime('%Y%m%d')], '基金代码': [fund_code], '收盘价': [result]}df = pandas.DataFrame(data)df_all = pandas.concat([df_all, df], ignore_index=True)target_df = df_combiner(target_path, df_all, sheet_name)excel_writer = pandas.ExcelWriter(target_path)target_df.to_excel(excel_writer, index=False, sheet_name='基金收盘价')excel_writer.close()if __name__ == '__main__':main()

三、展示

将获取的excel数据展示成折线图,这里使用的是pyecharts,不多废话直接上代码

# https://pyecharts.org/#/zh-cn/quickstart
import numpy
import pandas
from pyecharts import options as opts
from pyecharts.charts import Linetarget_path = r'excel位置'
sheet_name = '基金收盘价'
fund_code_list = ['sh510300', 'sz159995']
tar_data_frame = pandas.DataFrame(pandas.read_excel(target_path, sheet_name=sheet_name, keep_default_na=False))
data_date = list(set(numpy.array(tar_data_frame['日期']).tolist()))
sh510300_date = numpy.array(tar_data_frame.loc[tar_data_frame['基金代码'] == 'sh510300']['收盘价']).tolist()
sz159995_date = numpy.array(tar_data_frame.loc[tar_data_frame['基金代码'] == 'sz159995']['收盘价']).tolist()# 创建柱状图
bar_chart = Line()
bar_chart.add_xaxis(data_date)
title_opts = opts.TitleOpts(title="月度销售额折线图"),
bar_chart.add_yaxis(series_name='sh510300', linestyle_opts=opts.LineStyleOpts(color="red", width=2, is_show=True), itemstyle_opts=opts.ItemStyleOpts(color="red", border_width=1), is_smooth=True, y_axis=sh510300_date)
bar_chart.add_yaxis(series_name='sz159995_date', linestyle_opts=opts.LineStyleOpts(color="yellow", width=2, is_show=True), itemstyle_opts=opts.ItemStyleOpts(color="yellow", border_width=1), is_smooth=True, y_axis=sz159995_date)
bar_chart.set_global_opts(title_opts=opts.TitleOpts(title="基金收盘价格走势", is_show=True, pos_left='center'), xaxis_opts=opts.AxisOpts(name="月份"), yaxis_opts=opts.AxisOpts(name="收盘价(元)", min_=0, max_=10), legend_opts=opts.LegendOpts(pos_left='right'))# 渲染图表到 HTML 文件
bar_chart.render("基金收盘价.html")

展示结果如下:
在这里插入图片描述

http://www.yayakq.cn/news/216704/

相关文章:

  • 房地产型网站建设报价学php网站开发
  • 深圳金鼎网站建设wordpress博客站模板下载
  • 天津企悦在线网站建设wordpress分类目录加图标
  • vp代理商网站管理系统销售网站建设的意义
  • 漳州模板网站建设网站建设有哪些需求
  • 如何做网站的营销公司网站建设的系统功能需求
  • 做金融类网站企业管理制度标准范本
  • 贵阳市网站优化wordpress 不要动态链接
  • 做教育导航的网站google play下载安装
  • 淘宝网站的建设目的郑州的设计公司
  • 装修网站开发聊城网站制作公司电话
  • 昆明做网站公司哪家好自己有域名服务器怎样建设网站
  • 商丘网站优化公司织梦调用wordpress
  • 免费推广网站大全下载广州北京网站建设公司
  • asp怎么样做网站后台国际新闻最新消息今天 新闻
  • 模拟网站平台怎么做怎么样网站速度快
  • 1免费网站建站北京市建设资格与执业资格注册中心网站
  • 建电商网站室内设计女孩子学难吗
  • 做网站实训心得体会做网站可以用什么数据库
  • 保定网站seo技术自己做的网站如何推广
  • 广州专业的做网站公司二建专业有哪些专业
  • 网站备案 公司网站开发调用别人网站的组件
  • 开封市建设局网站广撒网网站
  • 个人网站制作网站企业查询员工社保缴费记录
  • 电子商务网站建设与实践考试自适应网页和响应式网页区别
  • 南充网站建设114加拿大28网站建设
  • 领动做的网站怎么样平泉建设局网站
  • 阿里做网站怎么做宁波如何做seo排名优化
  • 购买一个网站需要多少钱企业网络营销策划方案费用
  • 公司网站建设费用会计处理哪家代理注册公司好