gpt4 book ai didi

python - 将 DataFrame 的结果输出到 QLabel

转载 作者:行者123 更新时间:2023-12-01 06:32:12 24 4
gpt4 key购买 nike

我有一个 Pandas DataFrame,可以在 Python 控制台中正确输出,但是我正在使用 QT 设计器创建一个应用程序,并希望此 DataFrame 在 QLabel 上输出,该标签称为:

<widget class="QLabel" name="LBL_RESULT">. 

我需要使用其他小部件类型来显示 DataFrame 吗?

我的代码是:

df=pd.DataFrame({"Identifier":id,"Description":desc})
print(df.to_string()) # prints everything to screen, not just the first page and last page.
df.to_csv('Test.txt',index=False) # saves the DataFrame to a text file
self.LBL_RESULT.setText(df)

错误是:

self.LBL_RESULT.setText(df)
TypeError: setText(self, str): argument 1 has unexpected type 'DataFrame'

请您帮忙。谢谢。

最佳答案

正如错误指出的那样,QLabel 不需要数据帧,而是字符串,因此您必须传递 to_string() 的结果:

df = pd.DataFrame({"Identifier":id,"Description":desc})
df.to_csv('Test.txt',index=False) # saves the DataFrame to a text file
self.LBL_RESULT.setText(<b>df.to_string()</b>)
self.LBL_RESULT.adjustSize()

关于python - 将 DataFrame 的结果输出到 QLabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59844358/

24 4 0
文章推荐: Jquery延迟CSS div位置
文章推荐: asp.net-mvc-4 - 多种语言的错误信息
文章推荐: java - Java 中的概率为 75%
文章推荐: jquery - 如何用jquery替换中除
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com