My data frame looks like below:
Airport | ATA Cost | Destination Handling | Custom | Total Cost |
---|---|---|---|---|
PRG | 599222 | 11095 | 20174 | 630491 |
LXU | 364715 | 11598 | 11595 | 387908 |
AMS | 401382 | 23562 | 16680 | 441623 |
PRG | 599222 | 11095 | 20174 | 630491 |
Using below codes it gives a stacked bar chart:
import pandas as pd
# sample dataframe
data = {'Airport': ['PRG', 'LXU', 'AMS', 'PRG'],
'ATA Cost': [599222, 364715, 401382, 599222],
'Destination Handling': [11095, 11598, 23562, 11095],
'Custom': [20174, 11595, 16680, 20174],
'Total Cost': [630491, 387908, 441623, 630491]}
df = pd.DataFrame(data)
# plot columns without Total Cost
df.iloc[:, :-1].plot(x='Airport', kind='barh', stacked=True, title='Breakdown of Costs', mark_right=True)
How to add the totals (separated by thousands 1,000) over each stacked bar chart? How to add %
for each segments in the stacked bar chart?