0

I have a pandas df which is 30x65 with each row representing an income bracket and each column representing a city. The data is made up of counts of the number of people who fit into each bracket from each city with some brackets having NaN. I would like to create a graph for each count income bracket with the city's being on the x axis whilst ignoring all NaN values. An example DF could be:

data = {'Name':['London', 'Liverpool', 'France', 'Berlin'],
        '0-10k':[20.0, 21.0, 19.0, None],
        '10-20k':[30.0, 50.0, None, 1.0],
        '20-30k':[2.0, None, None, 3]}

df = pd.DataFrame(data)

df

I've been trying a bunch of things to no avail as most of the time the graphs are too squished together to even be able to tell the variables apart. But I would like a bar visualisation for each income bracket and the variable as the city.

Many Thanks.

1 Answers1

0

enter image description hereIn the comment I have put the stackoverflow link which helped me. Kindly give it a read. I used the following code to come to a probable soultion:

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

sns.set_theme(style="darkgrid")

data = {'Name':['London', 'Liverpool', 'France', 'Berlin'],
        '0-10k':[20.0, 21.0, 19.0, None],
        '10-20k':[30.0, 50.0, None, 1.0],
        '20-30k':[2.0, None, None, 3]}

df = pd.DataFrame(data)

df.set_index('Name').plot(kind='bar', stacked=True)

plt.show()

Please see the output image: