whats wrong with the graph I wanted to plot a bar graph which shows covid cases reported in different regions in different regions of USA.
So here is my code:
import pandas as pd
import matplotlib.pyplot as plt
datainput = pd.read_csv(&quot;MD_COVID-19.csv&quot;)
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
rgn1=list(datainput['Allegany'])
rgn2=list(datainput['Anne_Arundel'])
rgn3=list(datainput['Baltimore'])
rgn4=list(datainput['Baltimore_City'])
rgn5=list(datainput['Calvert'])
rgn6=list(datainput['Caroline'])
rgn7=list(datainput['Washington'])
region=['Allegany','Anne_Arundel','Baltimore','Baltimore_City','Calvert','Caroline','Washington']
rgn1s=0
rgn2s=0
rgn3s=0
rgn4s=0
rgn5s=0
rgn6s=0
rgn7s=0
for item in rgn1:
 rgn1s +=item
for item in rgn2:
 rgn2s +=item
for item in rgn3:
 rgn3s +=item
for item in rgn4:
 rgn4s +=item
for item in rgn5:
 rgn5s +=item
for item in rgn6:
 rgn6s +=item
for item in rgn7:
 rgn7s +=item
tc=[]
tc.append(rgn1s)
tc.append(rgn2s)
tc.append(rgn3s)
tc.append(rgn4s)
tc.append(rgn5s)
tc.append(rgn6s)
tc.append(rgn7s)
ax.bar(region,tc)
plt.ylabel(&quot;Number of Cases&quot;)
plt.show()

My bar graph is shown as above. Why are only three bar graphs coming?
Where are the other four? Also how can I draw pie chart?
The reason the other bars are missing is because of your method of summing the values and the missing values in your dataset. The way you are adding the values together means that if even one value is missing (NA) the total for that column will be missing as well, and as a result, will not be in your final plot. It is better to use pandas built-in methods (for conciseness, speed, but also to avoid errors such as the one you encountered) to add up the values as follows (using random values):
import pandas as pd
import matplotlib.pyplot as plt

datainput = pd.read_csv(&quot;MD_COVID-19.csv&quot;)
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
regions = ['Allegany', 'Anne_Arundel', 'Baltimore', 'Baltimore_City', 'Calvert', 'Caroline', 'Washington']
# select all region columns and calculate the sum column-wise
total_cases = datainput[regions].sum()
ax.bar(regions, total_cases)
plt.ylabel(&quot;Number of Cases&quot;)
plt.show()

Which gives the following result: