问题描述
我有一个[.xls]格式的excel工作表,其中包含来自软件的实时股票数据流。 我想每5秒读取并处理python中工作表中的数据。
仅当我手动保存.xls文件时,Python才会获取刷新的数据。第一次之后,它不会在运行的脚本上自动获取新的数据点。
有帮助吗?
解决方法
这应该可以帮助您:
import threading
import pandas as pd
def main_task():
threading.Timer(5.0,main_task).start() #Repeats the function main_task every 5 seconds
df = pd.read_excel("filename.xls") #Reads the excel file
main_task() #Calls the function
此代码将每5秒钟用新值更新您的pandas DataFrame。