本文介绍了如何在简单的 Kivy 应用程序中将 Pandas 数据框显示为表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想构建一个简单的 Kivy 应用:
I would like to build a simple Kivy app that:
- 要求用户输入一个整数 (MTP)
- 要求用户输入延迟间隔(delay)
- 在用户按下提交按钮后查询一个url,然后从查询创建一个显示的熊猫数据框(如表)在 Kivy 应用程序的主屏幕上,然后输出更新数据帧,直到 MTP 和延迟间隔结束
我将查询的所有代码用作常规 python 程序,我只是不知道如何显示用户输入和输出数据帧(和时间戳).(见下文)
I have all the code functioning for the query as a regular python program, I just don't know how to have the user input and the output dataframe (and a time stamp) displayed. (See below)
import requests
import time
from bs4 import BeautifulSoup
from datetime import datetime
import itertools
import pandas as pd
mtp = input("Input whole number of minutes to post:") #<-How to do on Kivy Screen
delay = input("Enter 15, 30 or 60 second delay:") #<-How to ask on Kivy Screen
STP = int(mtp)*60
def requestOdds():
url = "https://WEBPAGE WITH ODDS DATA.aspx"
r = requests.get(url)
soup = BeautifulSoup(r.content)
stamp = datetime.now().strftime('%m/%d %H:%M:%S')
tbPPosts = ('rptOdds_ctl01_tdOdd', 'rptOdds_ctl02_tdOdd','rptOdds_ctl03_tdOdd','rptOdds_ctl04_tdOdd','rptOdds_ctl05_tdOdd','rptOdds_ctl06_tdOdd','rptOdds_ctl07_tdOdd','rptOdds_ctl08_tdOdd','rptOdds_ctl09_tdOdd','rptOdds_ctl10_tdOdd','rptOdds_ctl11_tdOdd','rptOdds_ctl12_tdOdd','rptOdds_ct113_tdOdd','rptOdds_ct114_tdOdd','rptOdds_ct115_tdOdd','rptOdds_ct116_tdOdd','rptOdds_ct117_tdOdd','rptOdds_ct118_tdOdd','rptOdds_ct119_tdOdd','rptOdds_ct120_tdOdd','rptOdds_ct121_tdOdd')
mlPPosts = ('rptOdds_ctl01_tdMl','rptOdds_ctl02_tdMl','rptOdds_ctl03_tdMl','rptOdds_ctl04_tdMl','rptOdds_ctl05_tdMl','rptOdds_ctl06_tdMl','rptOdds_ctl07_tdMl','rptOdds_ctl08_tdMl','rptOdds_ctl09_tdOdd','rptOdds_ctl10_tdMl','rptOdds_ctl11_tdMl','rptOdds_ctl12_tdMl','rptOdds_ct113_tdMl','rptOdds_ct114_tdMl','rptOdds_ct115_tdMl','rptOdds_ct116_tdMl', 'rptOdds_ct117_tdMl','rptOdds_ct118_tdMl','rptOdds_ct119_tdMl','rptOdds_ct120_tdMl','rptOdds_ct121_tdMl')
trimmed_text=[]
trimmed_text2=[]
tbodds = []
mlodds = []
odds = []
for horse in tbPPosts:
table = soup.find('td', {"odds-table-odd"}, id=horse)
if table is not None:
text = table.renderContents()
trimmed_text = text.strip()
tbodds.append(trimmed_text)
for mlhorse in mlPPosts:
table2 = soup.find('td', {"odds-table-ml"}, id=mlhorse)
if table2 is not None:
text2 = table2.renderContents()
trimmed_text2 = text2.strip()
mlodds.append(trimmed_text2)
mlodds = itertools.ifilterfalse(lambda x: x=='', mlodds) #faster
tbodds = itertools.ifilterfalse(lambda x: x=='', tbodds)
oddsDict = dict(zip(mlodds, tbodds))
**odds = pd.DataFrame(list(oddsDict.iteritems()), columns=['ML','TB'])
print odds, stamp** #<--How do I get these to print onto the Kivy Screen?
def getLiveOdds():
interval = 0
while interval <= STP:
requestOdds()
time.sleep(delay)
interval +=delay
getLiveOdds()
任何帮助将不胜感激!
推荐答案
我发现了一些可以帮助你的东西:
I found out something which could help you :
基维文件
GraphDraw:
<GraphDraw>:
BoxLayout:
Button:
text: "Hello World"
on_press: root.graph()
逻辑
#!/usr/bin/env python
# -*- encoding: utf-8
import datetime
import pandas as pd
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
import dfgui
import pandas as pd
class Visualisation(App):
pass
class GraphDraw(BoxLayout):
def graph(self):
xls = pd.read_excel('filepath')
#df = pd.DataFrame.xls
dfgui.show(xls)
#print xls
if __name__ == '__main__':
Visualisation().run()
所以您使用 dfgui 可以创建 pandas 数据框表,而不是使用 Kivy.查看项目 dfgui:https://github.com/bluenote10/PandasDataFrameGUI
So you use dfgui which can create pandas dataframe table instead of using Kivy.See the project dfgui : https://github.com/bluenote10/PandasDataFrameGUI
希望对你有帮助:)
这篇关于如何在简单的 Kivy 应用程序中将 Pandas 数据框显示为表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!