Kivy 显示从 pandas 到 Kivy 的数据

Kivy Display Data from pandas to Kivy

我准备好从 pandas 数据库中显示一些数据,我想让它看起来不错,但我只能将其打印为标签。看起来很糟糕。我也想让它滚动,但我在 Kivy 中是全新的。我无法在互联网上使用任何解决方案。这是我的代码。

我希望有某种库可以处理 pandas 到 Kivy,但我看不到那样的东西。

如有任何建议,我们将不胜感激 先感谢您。

class ScatterTextWidget(BoxLayout):

''' this part we take the information from timestation website and start analyze it '''

    item_to_display = ObjectProperty()
    text_location = ObjectProperty()
    input_date = ObjectProperty()
    input_time = ObjectProperty()

    def initialize_request(self):
        ''' Initial analysis and control flow of the class '''

        location = self.text_location.text
        date = self.input_date.text
        time_raw = self.input_time.text

        url = 'test.csv'

        data = pd.read_csv(url)
        time = self.time_format_checker(time_d=time_raw)
        group_name = data[data["Time"] <= time]
        duplicates_removed = group_name.drop_duplicates(subset="Name", keep='last')
        punch_in_df = duplicates_removed[duplicates_removed.Activity.str.contains('Punch In')]
        filtered_data = punch_in_df[punch_in_df.Department.str.contains(location)]
        filtered_data.reset_index(inplace=True)
        self.item_to_display.text = filtered_data[['Name', 'Department', 'Device', 'Time']].to_string()

这是 kivy 文件 --- 简短版本:

#:import utils kivy.utils
#:import ListAdapter kivy.adapters.listadapter.ListAdapter
#:import ListItemButton kivy.uix.listview.ListItemButton
#:import main MainGui


<ScatterTextWidget>:

    text_location:text_location
    item_to_display:item_to_display
    input_date:input_date
    input_time:input_time


    canvas.before:
        Color:
             rgb: utils.get_color_from_hex('#000131')
        Rectangle:
            pos: self.pos
            size: self.size

    BoxLayout:
         orientation: "vertical"

        BoxLayout:
            canvas.before:
                 Color:
                    rgb: utils.get_color_from_hex('#00050c')
                 Rectangle:
                    pos: self.pos
                    size: self.size

            Label:
                id:item_to_display
                pos_hint_y: 'top'
                size_hint_y: .75
                text: 'Please introduce the Date'

我希望得到这样的东西:

Name               | Department   | Device      | Time |
Rodriguez, Cesar   |IT Department | IT Office   | 6:00 |
Clarke, Gyles      |Kent Avenue   | Kent Device | 7:00 |

你检查过这个模块了吗DataframeGUIKivy

您可以使用此模块在 Kivy 中显示 pandas 数据框。