1

I have a Pandas DataFrame that outputs correctly in the Python console, however I'm creating an application using QT designer and would like this DataFrame to be output on a QLabel, the label is called:

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

Do I need to use another widget type to display the DataFrame?

The code I have is:

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)

The error is:

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

Please can you assist. Thanks.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
MB4ig
  • 65
  • 5

1 Answers1

1

As the error points out, QLabel does not expect a dataframe but a string, so you must pass the result of 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()
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Thank you so much! The quick response is much appreciated, this works perfectly. Thanks for explaining :) – MB4ig Jan 21 '20 at 17:04