接着006,有一些问题,要手动改文件,麻烦,直接出来一个按钮,点击出现弹窗可以选择文件。
二来就是,所统计的数据,没有展示细节。应该展示的细节包括:股票代码,K线周期,连续跌三天的次数。
import tkinter as tk
from tkinter import filedialog
import pandas as pd
path=''
def open_file():
global path
path = filedialog.askopenfilename(initialdir="./", title="Select file", filetypes=(("Text files", "*"), ("All files", "*.*")))
print("Selected file:", path)
root.quit() # 选择完文件后退出主循环
root = tk.Tk()
root.title("File Selector")
button = tk.Button(root, text="Open File", command=open_file)
button.pack()
root.mainloop()
# 读取表格数据
data = pd.read_csv(path, delimiter=',')
# 初始化计数器
total_count = 0
up_count = 0
# 遍历数据
for i in range(len(data)-3):
# 判断是否连续三天下跌
if data['涨跌幅'][i] < 0 and data['涨跌幅'][i+1] < 0 and data['涨跌幅'][i+2] < 0:
total_count += 1
# 判断第四天是否上涨
if data['涨跌幅'][i+3] > 0:
up_count += 1
# 计算概率
probability = up_count / total_count
print("K线总数:",len(data))
print("连续三天下跌的次数为:", total_count)
print("连续三天下跌后,下一天上涨次数为:", up_count)
print("连续三天下跌后,下一天上涨的概率为:", probability)
print("出现连续三天下跌平均需要多少条K线:" , len(data)/total_count)
来看效果:
done