标签:min taf and price 读取 银行 走势 完成 a20
题目:
import pandas as pd
from pandas import to_datetime
import matplotlib.pyplot as plt
#读数据
data_read = pd.DataFrame(pd.read_csv(open("data.csv",‘r‘)))
data_read.drop([‘price_change‘,‘p_change‘,‘ma5‘,‘ma10‘,‘ma20‘,‘v_ma5‘,‘v_ma10‘,‘v_ma20‘],axis=1,inplace=True)
print(data_read)
#转化为python可以识别的日期格式
data_read[‘date‘] = pd.to_datetime(data_read[‘date‘])
#按照时间戳进行排序
data_read.sort_values(by = [‘date‘],ascending = True ,inplace = True)
#绘制折线图
plt.plot(data_read[‘date‘],data_read[‘close‘])
plt.xticks()
plt.xlabel("date")#x轴的文字说明
plt.ylabel("close")#y轴文字说明
plt.title("date-close")#此图像的标题
plt.show()
plt.close()
#输出volume最大的和最小的
data_read.sort_values(by = ‘volume‘,ascending=True,inplace=True)
volume_max = data_read[-1:]
volume_min = data_read[0:1]
print(volume_max)
print(volume_min)
#成交量在1000000以上的数据
volume_data = data_read[data_read[‘volume‘]>1000000]
print(volume_data)
#收盘价高于开盘价的天数
open_data = data_read[‘open‘]
close_data = data_read[‘close‘]
s=0
for i,op in enumerate(close_data):
if op > open_data[i]:
s = s + 1;
print("收盘价高于开盘价的天数为:",s)
data_read[‘date‘]=pd.to_datetime(data_read[‘date‘])
data_read = data_read.set_index(‘date‘)
volume_avg=[]
seven_volume = data_read[‘2018-07‘]
seven_temp = seven_volume[‘close‘]
seven_avg = seven_temp.mean(axis=0)
volume_avg.append(seven_avg)
eight_volume = data_read[‘2018-08‘]
eight_temp = eight_volume[‘close‘]
eight_avg = eight_temp.mean(axis=0)
volume_avg.append(eight_avg)
nine_volume = data_read[‘2018-09‘]
nine_temp = nine_volume[‘close‘]
nine_avg = nine_temp.mean(axis=0)
volume_avg.append(nine_avg)
ten_volume = data_read[‘2018-10‘]
ten_temp = ten_volume[‘close‘]
ten_avg = ten_temp.mean(axis=0)
volume_avg.append(ten_avg)
eleven_volume = data_read[‘2018-11‘]
eleven_temp = eleven_volume[‘close‘]
eleven_avg = eleven_temp.mean(axis=0)
volume_avg.append(eleven_avg)
twelve_volume = data_read[‘2018-12‘]
twelve_temp = twelve_volume[‘close‘]
twelve_avg = twelve_temp.mean(axis=0)
volume_avg.append(twelve_avg)
print("七到十二月的平均收盘价为:",volume_avg)
name_list = [‘July‘,‘Auguest‘,‘September‘,‘October‘,‘November‘,‘December‘]
plt.bar(range(len(volume_avg)),volume_avg,color = ‘rgb‘,tick_label = name_list)
plt.show()
标签:min taf and price 读取 银行 走势 完成 a20
原文地址:https://www.cnblogs.com/sunflowers-lanqijiu/p/11925232.html