首页 > 解决方案 > 如何从流式 excel 表解析为 python pandas df?

问题描述

我有一个 [.xls] 格式的 excel 表,其中包含来自软件的股票数据的实时流。我想每 5 秒后在 python 中读取和处理工作表中的数据。

仅当我手动保存 .xls 文件时,Python 才会获得刷新数据。第一次后,它不会自动在运行脚本上获取新数据点。

有什么帮助吗?

标签: pythonexcelpandaslive

解决方案


这应该可以帮助您:

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。


推荐阅读