python - 如何从流式 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。
推荐阅读
- geospatial - 如何使用 R 中的 Spatstat 将强度转换为点模式中的概率?
- eclipse - 如何在 Eclipse 运行配置中取消设置环境变量?
- join - 在第三个新表中加入 Spotfire 中的表
- node.js - 如何在sequelize中从多个表中删除记录?
- android - 如何在 Android 主题中正确设置两种不同的字体
- reactjs - SharePoint React pnpjs
- java - java - 不能从静态上下文引用非静态方法“getLogger”
- android - 实现有保证的重复后台工作的最佳方法 Android
- python - Python中的模板
- angular - 如何在角度2中的下拉列表的值和文本字段上添加所需的验证