程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Read stock excel and CSV data and draw pictures with pandas and pyecharts

編輯:Python

Data sources

https://www.lixinger.com/ You can download csv file
It should be noted that , Remember to delete the last of the first line The data comes from : Almond management website (lixinger.com) this sentence , Text and time series cannot be processed together

Excel

The first method

import pandas as pd
import matplotlib.pyplot as plt
# Need to install xlrd pip install xlrd==1.2.0
data = pd.read_excel('data/zhongzheng500.xlsx',sheet_name ='Sheet1',usecols=[0,2,4,5],index_col=[0])
#sheet_name Pass table name .usecols from 0 Start , Confirm to use column .index_col Use the 0 Column time as index 
data.plot(xticks=pd.date_range('2010-12-02','2020-12-02',freq='M'),rot=90)
# Show x The problem with the axis , And rotate 90 degree , Because I think there are too few default dates 
plt.rcParams['font.sans-serif']=['SimHei','SimSun'] # Show Chinese tags 
plt.rcParams['axes.unicode_minus']=False
plt.show()

Use data.plot(xticks=pd.date_range(‘2010-12-02’,‘2020-12-02’,freq=‘M’),rot=90) Image

Don't use data.plot(xticks=pd.date_range(‘2010-12-02’,‘2020-12-02’,freq=‘M’),rot=90)

The second method

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Need to install xlrd pip install xlrd==1.2.0
time = pd.read_excel('data/zz500zhishu.xlsx',sheet_name ='Sheet1',usecols=[0])
time_v = time.values
PE = pd.read_excel('data/zz500zhishu.xlsx',sheet_name ='Sheet1',usecols=[2])
PE_v = PE.values
PB = pd.read_excel('data/zz500zhishu.xlsx',sheet_name ='Sheet1',usecols=[4])
PB_v = PB.values
temp = pd.read_excel('data/zz500zhishu.xlsx',sheet_name ='Sheet1',usecols=[5])
temp_v = temp.values
plt.plot(time_v,PE_v)
plt.plot(time_v,PB_v)
plt.plot(time_v,temp_v)
plt.show()

Csv

import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('data/yiming.csv',na_values=0,index_col=[0],encoding='GBK',usecols=[0,1,2])
data.plot()
plt.rcParams['font.sans-serif']=['SimHei','SimSun'] # Show Chinese tags 
plt.rcParams['axes.unicode_minus']=False
# Show x The problem with the axis , And rotate 90 degree 
plt.show()

pyecharts drawing

from pyecharts import Line# pip install pyecharts==0.1.9.4
import numpy as np
import pandas as pd
def to_time(T):
time_LIST = []
for time in T:
temp=time.strftime('%Y-%m-%d')
time_LIST.append(temp)
return time_LIST
time = pd.read_excel('data/zz500zhishu.xlsx',sheet_name ='Sheet1',usecols=[0])
time_list = time[' Time '].to_list()# Convert it to list
time_v = to_time(time_list)
PE = pd.read_excel('data/zz500zhishu.xlsx',sheet_name ='Sheet1',usecols=[2])
PE_v = PE['PE temperature '].tolist()# Convert it to list
line=Line(" Broken line diagram ")
line.add('PE',time_v,PE_v,mark_point=["max","min"])
line.render('t.html')


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved