Plot table and Pandas Dataframe display
I want to display on my Pandas screen data on screen in tabular format:
df = pd.DataFrame({'apples': 10, 'bananas': 15, 'pears': 5}, [0])
I'm not sure how to do this. I know that pd.DataFrame.plot () has some options for displaying the table, but only together with the plot. I just want to display a table (i.e. Dataframe) on the screen. Thank!
EDIT:
Here is a screenshot of creating a table using Pandas' build function. I only want a portion of the bottom table, not a graph. I also need a table popup.
EDIT 2:
I was able to display my framework in a picture with the following:
plt.figure()
y = [0]
plt.table(cellText=[10, 15, 5], rowLabels=[0], columnLabels=['apple', 'bananas', 'pears'], loc='center')
plt.axis('off')
plt.plot(y)
plt.show()
This will only display the table without any axes. I don't know if this is the best way to do this, so any suggestions would be appreciated. Also, is there a way to add a title to this table? The only way I know is to use plt.text and put the text (table name) in the shape, but then I'll have to keep the axes ... Any ideas?
source to share
line 2-4 hide the graph above, but somehow the graph still saves some space for the shape
import matplotlib.pyplot as plt
ax = plt.subplot(111, frame_on=False)
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
the_table = plt.table(cellText=table_vals,
colWidths = [0.5]*len(col_labels),
rowLabels=row_labels, colLabels=col_labels,
cellLoc = 'center', rowLoc = 'center')
plt.show()
source to share