将熊猫与pyqt5一起使用。单击按钮,请获取信息并将其加载到屏幕

发布于 2025-02-11 17:02:52 字数 1523 浏览 1 评论 0原文

因此,我有一个带有转换按钮的基本应用程序。目前,我的输入我正在接受一个URL并将其取代为表(数据[2])。在我的功能中,当我单击“转换”按钮时,我想将这些数据粘贴到我的窗口应用程序上,但是正在遇到此错误,

TypeError: arguments did not match any overloaded call:
  QLabel(parent: QWidget = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type 'DataFrame'
  QLabel(str, parent: QWidget = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type 'DataFrame'

我该如何工作?

import pandas as pd
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QVBoxLayout, QPushButton, QLabel, QLineEdit, QWidget
app = QApplication([])
WIN = QWidget()
layout = QVBoxLayout()
WIN.setWindowTitle('Table')
WIN.setGeometry(100,100,500,500)
# 
url = input('Paste URL here: ')
data = pd.read_html(url)

date_grid = data[2]
print(date_grid)
# airlines = data['Airlines'].tolist()
# destinations = data['Destinations'].tolist()

text_box = QLineEdit()
label = QLabel('Paste a URL to convert to Excel')
convert_button = QPushButton('Convert')

layout.addWidget(label, alignment=Qt.AlignCenter)
layout.addWidget(text_box, alignment=Qt.AlignCenter)
layout.addWidget(convert_button, alignment=Qt.AlignCenter)
WIN.setLayout(layout)

text_box.setFixedHeight(35)
text_box.setFixedWidth(300)


def covert_btn():
    text = QLabel(date_grid)
    layout.addWidget(text, alignment=Qt.AlignCenter)
    WIN.setLayout(layout)


convert_button.clicked.connect(covert_btn)

# 
WIN.show()
app.exec_()

So I have a basic app with a convert button. Currently with my input I am accepting a URL and scrapping it for the tables (data[2]). In my function I want to paste this data on my window app when I click my 'convert' button but am getting this error

TypeError: arguments did not match any overloaded call:
  QLabel(parent: QWidget = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type 'DataFrame'
  QLabel(str, parent: QWidget = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type 'DataFrame'

How can I get this to work?

import pandas as pd
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QVBoxLayout, QPushButton, QLabel, QLineEdit, QWidget
app = QApplication([])
WIN = QWidget()
layout = QVBoxLayout()
WIN.setWindowTitle('Table')
WIN.setGeometry(100,100,500,500)
# 
url = input('Paste URL here: ')
data = pd.read_html(url)

date_grid = data[2]
print(date_grid)
# airlines = data['Airlines'].tolist()
# destinations = data['Destinations'].tolist()

text_box = QLineEdit()
label = QLabel('Paste a URL to convert to Excel')
convert_button = QPushButton('Convert')

layout.addWidget(label, alignment=Qt.AlignCenter)
layout.addWidget(text_box, alignment=Qt.AlignCenter)
layout.addWidget(convert_button, alignment=Qt.AlignCenter)
WIN.setLayout(layout)

text_box.setFixedHeight(35)
text_box.setFixedWidth(300)


def covert_btn():
    text = QLabel(date_grid)
    layout.addWidget(text, alignment=Qt.AlignCenter)
    WIN.setLayout(layout)


convert_button.clicked.connect(covert_btn)

# 
WIN.show()
app.exec_()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧话新听 2025-02-18 17:02:52

Qlabel需要String带有普通文本html

dataFrame具有函数.to_string()将其作为字符串(如在控制台中),

text = QLabel( date_grid.to_string() )

并且它也具有.to_html()获得它AS html

text = QLabel( date_grid.to_html() )

to_string()

”在此处输入图像描述“

to_html()

QLabel needs string with plain text or with HTML.

DataFrame has function .to_string() to get it as string (like in console),

text = QLabel( date_grid.to_string() )

and it also has .to_html() to get it as HTML

text = QLabel( date_grid.to_html() )

to_string()

enter image description here

to_html()

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文