我有一个在Python控制台中正确输出的Pandas DataFrame,但是我正在使用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'
请您提供协助。谢谢。
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(df.to_string())
self.LBL_RESULT.adjustSize()