0

I have the following table which shows the item and price for that item.

    item       CAR_PRIC1      Car_PRICE2
0   H1         17400.00       18400.00
1   H2         35450.00       27400.00
2   H3         55780.00       57400.00
3   H4         78500.00       37400.00
4   H5         25609.55       77400.00
5   H6         96000.00       97400.00

How I can draw a histogram to show on Y-axis a category of different prices and on X-Axis shows how many percentage of all contract falls among those category of prices. like following:

enter image description here

sahel
  • 201
  • 2
  • 8

1 Answers1

0

It's straightforward with seaborn displot (editing your df a bit to make the plot more readable):

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

data = {
    'item': {0: 'H1', 1: 'H2', 2: 'H3', 3: 'H4', 4: 'H5', 5: 'H6'},
    'CAR_PRICE1': {0: 7400.0, 1: 135450.0, 2: 5780.0, 3: 78500.0, 4: 25609.55, 5: 126000.0},
    'CAR_PRICE2': {0: 78400.0, 1: 27400.0, 2: 37600.0, 3: 37400.0, 4: 77400.0, 5: 97400.0}
    }

df = pd.DataFrame(data)

sns.displot(data=df[['CAR_PRICE1', 'CAR_PRICE2']])
plt.show()

Output:

enter image description here

If you want percentage instead of count:

sns.displot(data=df[['CAR_PRICE1', 'CAR_PRICE2']], stat='percent')
Tranbi
  • 11,407
  • 6
  • 16
  • 33