我在Python中编写了一个小程序,该程序在两个类别之间随机选择,并相应地子集数据帧。完成后,它会选择一行并提出问题和潜在的选择。问题和选项位于数据帧的行中的两个不同列下。到目前为止,它运行良好;问题是当我试图将其与kivy相结合时。
我不明白行动的顺序是如何发生的。基本上,我希望能够通过kivy文件在屏幕上包含问题和选择。到目前为止,我能够显示它们,但看起来问题中的值与选择列中的值不匹配。我的直觉告诉我,我的kivy文件运行“Choosing_category”两次,而不是只运行一次并获取适当的输出。有谁知道我该如何解决这个问题?
以下是我到目前为止所拥有的:
tryapp.py
import kivy
from kivy.app import App
import pandas as pd
import numpy as np
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
kivy.require('1.11.1')
class QuestionWindows(Screen):
def __init__(self, **kwargs):
super(QuestionWindows, self).__init__(**kwargs)
self.prob = ''
self.word = ''
self.choice1 = ''
self.word = ''
self.df = pd.DataFrame()
def _get_df(self):
df = pd.DataFrame([['new', 'What is you favorite color?', 'blue?', 'blue', 0,0,0,0,0],
['familiar', 'What is your favorite fruit?', 'apple?', 'apple', 0,0,0,0,0],
['new', 'What is your favorite vegetable?', 'carrot?', 'carrot',0,0,0,0,0]],
columns=['state', 'questions', 'choice1', 'answer', 'cnt', 'count_correct', 'error_count', 'total_error', 'total_correct'])
return df
def choosing_category(self):
# Loading the dataframe
self.df = self._get_df()
# Generating the category for which the question/answer will be sampled from
self.prob = np.random.choice(['new', 'familiar'], 1, p=[0.7, 0.3])
# Dealing with the condition on whether the state 'familiar' is not found in the data set
if self.prob not in self.df['state'].values:
self.prob = ['new']
self.prob = self.prob
蓝山帝景
芜湖不芜
随时随地看视频慕课网APP
相关分类