Python pandas summary table plot
Can't really figure out how to build pandas df pivot table. I'm pretty sure this is not the case for a pivot table, or maybe a transposed method for displaying data. The best I could find this: Table and pandas Dataframe display My code attempts just don't get through :
dc = pd.DataFrame({'A' : [1, 2, 3, 4],'B' : [4, 3, 2, 1],'C' : [4, 3, 2, 1]})
data = dc['A'],dc['B'],dc['C']
ax = plt.subplot(111, frame_on=False)
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
cols=["A", "B", "C"]
row_labels=[0]
the_table = plt.table(cellText=data,colWidths = [0.5]*len(cols),rowLabels=row_labels, colLabels=cols,cellLoc = 'center', rowLoc = 'center')
plt.show()
All I would like to do is create a tabular graph containing the ABC in the first column and the total and average in the rows next to them (see below). Any help or guidance would be great ... feeling really stupid ... (sorry code example, it doesn't have overall and average value yet, but included ...)
Total Mean
A x x
B x x
C x x
source to share
import pandas as pd
import matplotlib.pyplot as plt
dc = pd.DataFrame({'A' : [1, 2, 3, 4],'B' : [4, 3, 2, 1],'C' : [3, 4, 2, 2]})
plt.plot(dc)
plt.legend(dc.columns)
dcsummary = pd.DataFrame([dc.mean(), dc.sum()],index=['Mean','Total'])
plt.table(cellText=dcsummary.values,colWidths = [0.25]*len(dc.columns),
rowLabels=dcsummary.index,
colLabels=dcsummary.columns,
cellLoc = 'center', rowLoc = 'center',
loc='top')
fig = plt.gcf()
plt.show()
source to share
Does the function help you dataFrame.describe()
?
http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.describe.html
Sorry, not enough points for comments.
source to share