Pentium10
Pentium10

Reputation: 207952

Matplotlib - How to draw table bar chart

Coming from a SQL backend, I have the below information in a dataframe.

How can I plot a table with bar charts?

enter image description here

Upvotes: 0

Views: 687

Answers (1)

Xukrao
Xukrao

Reputation: 8634

One way is to use the built-in styling functionality of pandas dataframes. Below is an example taken from the pandas documentation.

import pandas as pd
import numpy as np

np.random.seed(24)
df = pd.DataFrame({'A': np.linspace(1, 10, 10)})
df = pd.concat([df, pd.DataFrame(np.random.randn(10, 4), columns=list('BCDE'))],
               axis=1)
df.iloc[0, 2] = np.nan

df.style.bar(subset=['A', 'B'], color='#d65f5f')

produces the following HTML output:

enter image description here

Upvotes: 2

Related Questions