python實現(xiàn)股票歷史數(shù)據(jù)可視化分析案例
更新時間:2021年06月10日 11:27:30 作者:榮仔!最靚的仔!
股票交易數(shù)據(jù)分析可直觀股市走向,對于如何把握股票行情,快速解讀股票交易數(shù)據(jù)有不可替代的作用,感興趣的可以了解一下
投資有風險,選擇需謹慎。 股票交易數(shù)據(jù)分析可直觀股市走向,對于如何把握股票行情,快速解讀股票交易數(shù)據(jù)有不可替代的作用!
1 數(shù)據(jù)預處理
1.1 股票歷史數(shù)據(jù)csv文件讀取
import pandas as pd import csv
df = pd.read_csv("/home/kesci/input/maotai4154/maotai.csv")

1.2 關鍵數(shù)據(jù)——在csv文件中選擇性提取“列”
df_high_low = df[['date','high','low']]

1.3 數(shù)據(jù)類型轉換
df_high_low_array = np.array(df_high_low) df_high_low_list =df_high_low_array.tolist()

1.4 數(shù)據(jù)按列提取并累加性存入列表
price_dates, heigh_prices, low_prices = [], [], []
for content in zip(df_high_low_list):
price_date = content[0][0]
heigh_price = content[0][1]
low_price = content[0][2]
price_dates.append(price_date)
heigh_prices.append(heigh_price)
low_prices.append(low_price)


2 pyecharts實現(xiàn)數(shù)據(jù)可視化
2.1 導入庫
import pyecharts.options as opts from pyecharts.charts import Line
2.2 初始化畫布
Line(init_opts=opts.InitOpts(width="1200px", height="600px"))
2.3 根據(jù)需要傳入關鍵性數(shù)據(jù)并畫圖
.add_yaxis(
series_name="最低價",
y_axis=low_prices,
markpoint_opts=opts.MarkPointOpts(
data=[opts.MarkPointItem(value=-2, name="周最低", x=1, y=-1.5)]
),
markline_opts=opts.MarkLineOpts(
data=[
opts.MarkLineItem(type_="average", name="平均值"),
opts.MarkLineItem(symbol="none", x="90%", y="max"),
opts.MarkLineItem(symbol="circle", type_="max", name="最高點"),
]
),
)
tooltip_opts=opts.TooltipOpts(trigger="axis"), toolbox_opts=opts.ToolboxOpts(is_show=True), xaxis_opts=opts.AxisOpts(type_="category", boundary_gap=True)
2.4 將生成的文件形成HTML代碼并下載
.render("HTML名字填這里.html")
![]()
2.5 完整代碼展示
import pyecharts.options as opts
from pyecharts.charts import Line
(
Line(init_opts=opts.InitOpts(width="1200px", height="600px"))
.add_xaxis(xaxis_data=price_dates)
.add_yaxis(
series_name="最高價",
y_axis=heigh_prices,
markpoint_opts=opts.MarkPointOpts(
data=[
opts.MarkPointItem(type_="max", name="最大值"),
opts.MarkPointItem(type_="min", name="最小值"),
]
),
markline_opts=opts.MarkLineOpts(
data=[opts.MarkLineItem(type_="average", name="平均值")]
),
)
.add_yaxis(
series_name="最低價",
y_axis=low_prices,
markpoint_opts=opts.MarkPointOpts(
data=[opts.MarkPointItem(value=-2, name="周最低", x=1, y=-1.5)]
),
markline_opts=opts.MarkLineOpts(
data=[
opts.MarkLineItem(type_="average", name="平均值"),
opts.MarkLineItem(symbol="none", x="90%", y="max"),
opts.MarkLineItem(symbol="circle", type_="max", name="最高點"),
]
),
)
.set_global_opts(
title_opts=opts.TitleOpts(title="茅臺股票歷史數(shù)據(jù)可視化", subtitle="日期、最高價、最低價可視化"),
tooltip_opts=opts.TooltipOpts(trigger="axis"),
toolbox_opts=opts.ToolboxOpts(is_show=True),
xaxis_opts=opts.AxisOpts(type_="category", boundary_gap=True),
)
.render("everyDayPrice_change_line_chart2.html")
)
3 結果展示
![]()


到此這篇關于python實現(xiàn)股票歷史數(shù)據(jù)可視化分析案例的文章就介紹到這了,更多相關python股票數(shù)據(jù)可視化內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Django的數(shù)據(jù)模型訪問多對多鍵值的方法
這篇文章主要介紹了Django的數(shù)據(jù)模型訪問多對多鍵值的方法,Django是Python豐富多彩的web框架中最具人氣的一個,需要的朋友可以參考下2015-07-07
python 解決動態(tài)的定義變量名,并給其賦值的方法(大數(shù)據(jù)處理)
今天小編就為大家分享一篇python 解決動態(tài)的定義變量名,并給其賦值的方法(大數(shù)據(jù)處理),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-11-11
解決pip install中UnicodeDecodeError問題的處理
這篇文章主要介紹了解決pip install中UnicodeDecodeError問題的處理,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-09-09
使用Python微信庫itchat獲得好友和群組已撤回的消息
這篇文章主要介紹了使用Python微信庫itchat獲得好友和群組已撤回的消息,需要的朋友可以參考下2018-06-06

