python實(shí)現(xiàn)股票歷史數(shù)據(jù)可視化分析案例
投資有風(fēng)險(xiǎn),選擇需謹(jǐn)慎。 股票交易數(shù)據(jù)分析可直觀股市走向,對(duì)于如何把握股票行情,快速解讀股票交易數(shù)據(jù)有不可替代的作用!
1 數(shù)據(jù)預(yù)處理
1.1 股票歷史數(shù)據(jù)csv文件讀取
import pandas as pd import csv
df = pd.read_csv("/home/kesci/input/maotai4154/maotai.csv")
1.2 關(guān)鍵數(shù)據(jù)——在csv文件中選擇性提取“列”
df_high_low = df[['date','high','low']]
1.3 數(shù)據(jù)類型轉(zhuǎn)換
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實(shí)現(xiàn)數(shù)據(jù)可視化
2.1 導(dǎo)入庫
import pyecharts.options as opts from pyecharts.charts import Line
2.2 初始化畫布
Line(init_opts=opts.InitOpts(width="1200px", height="600px"))
2.3 根據(jù)需要傳入關(guān)鍵性數(shù)據(jù)并畫圖
.add_yaxis( series_name="最低價(jià)", 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="最高點(diǎn)"), ] ), )
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="最高價(jià)", 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="最低價(jià)", 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="最高點(diǎn)"), ] ), ) .set_global_opts( title_opts=opts.TitleOpts(title="茅臺(tái)股票歷史數(shù)據(jù)可視化", subtitle="日期、最高價(jià)、最低價(jià)可視化"), 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 結(jié)果展示
到此這篇關(guān)于python實(shí)現(xiàn)股票歷史數(shù)據(jù)可視化分析案例的文章就介紹到這了,更多相關(guān)python股票數(shù)據(jù)可視化內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Python實(shí)戰(zhàn)實(shí)現(xiàn)爬取天氣數(shù)據(jù)并完成可視化分析詳解
- Python?數(shù)據(jù)可視化超詳細(xì)講解折線圖的實(shí)現(xiàn)
- Python?echarts實(shí)現(xiàn)數(shù)據(jù)可視化實(shí)例詳解
- Python實(shí)現(xiàn)爬取天氣數(shù)據(jù)并可視化分析
- Python?數(shù)據(jù)可視化實(shí)現(xiàn)5種炫酷的動(dòng)態(tài)圖
- 基于Python實(shí)現(xiàn)股票數(shù)據(jù)分析的可視化
- Python實(shí)現(xiàn)數(shù)據(jù)可視化案例分析
相關(guān)文章
Python基礎(chǔ)實(shí)戰(zhàn)總結(jié)
今天要給大家介紹的是Python基礎(chǔ)實(shí)戰(zhàn),本文主要以舉例說明講解:問題的關(guān)鍵點(diǎn)就是在于構(gòu)造姓名,學(xué)號(hào)和成績,之后以字典的形式進(jìn)行寫入文件。這里準(zhǔn)備兩個(gè)列表,一個(gè)姓,一個(gè)名,之后使用random庫進(jìn)行隨機(jī)字符串拼接,得到姓名,需要的朋友可以參考一下2021-10-10Pycharm使用Database?Navigator連接mysql數(shù)據(jù)庫全過程
這篇文章主要介紹了Pycharm使用Database?Navigator連接mysql數(shù)據(jù)庫全過程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07python實(shí)現(xiàn)凱撒密碼、凱撒加解密算法
這篇文章主要介紹了python語言編程實(shí)現(xiàn)凱撒密碼、凱撒加解密算法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06NumPy統(tǒng)計(jì)函數(shù)的實(shí)現(xiàn)方法
這篇文章主要介紹了NumPy統(tǒng)計(jì)函數(shù)的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01Python Sleep休眠函數(shù)使用簡單實(shí)例
這篇文章主要介紹了Python Sleep休眠函數(shù)使用簡單實(shí)例,本文直接給出兩個(gè)實(shí)現(xiàn)例子,需要的朋友可以參考下2015-02-02python2 與 pyhton3的輸入語句寫法小結(jié)
這篇文章主要給大家介紹了關(guān)于python2 與 pyhton3的輸入語句寫法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-09-09