如何从流Excel表格解析到python pandas df?

问题描述

我有一个[.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。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...