0

Please see what,s wrong with my code So here is my code:

import pandas as pd
import matplotlib.pyplot as plt
di = pd.read_csv("iris.csv")
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
sl=list(datainput['sepal_length'])
sw=list(datainput['sepal_width'])
c=['sepal_length','sepal_width']
sl=0
sw=0
plt.ylabel("Number")
plt.show()
Anonymous
  • 82
  • 2
  • 11
  • here's one tip (you don't actually need): `rgn1=list(datainput['Allegany']); rgn1s = len(rng1)` – Paul H Jan 27 '21 at 17:06
  • 1
    here's the tip you actually need: `pd.read_csv("MD_COVID-19.csv").count().plot.bar()` – Paul H Jan 27 '21 at 17:07
  • If you want more specific help, you need to make your example reproducible: https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples (right now, no one but you can create your dataframe) – Paul H Jan 27 '21 at 17:08
  • may I know what is wrong in my approach?? – Anonymous Jan 27 '21 at 17:14
  • build an reproducible example and i'll show you (it's hard to put into words) – Paul H Jan 27 '21 at 17:15
  • what is reproducible example? I couldnt understand – Anonymous Jan 27 '21 at 17:17
  • I provided you with a link in a comment above. I recommend reading that question and its answers carefully – Paul H Jan 27 '21 at 17:20
  • I have given some part of data please see it – Anonymous Jan 27 '21 at 17:33
  • 2
    You posted a screen shot. Do you expect me to type that out myself? Please provide the data as recommended in the link I provided – Paul H Jan 27 '21 at 17:59
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/227952/discussion-between-dolly6-and-paul-h). – Anonymous Jan 28 '21 at 10:34

2 Answers2

0

I tested your code with a different csv file where all the columns had the same length and it plotted the correct number of bars. I suspect that's the source of the problem since you only have 3 complete columns in your data. Also, lines 15 through 43 of your code (all the for loops and append statements) can be replaced with a single line:

tc = [sum(rgn1), sum(rgn2), sum(rgn3), sum(rgn4), sum(rgn5), sum(rgn6), sum(rgn7)]
pakpe
  • 5,391
  • 2
  • 8
  • 23
0

Little hard to reproduce, but i think the problem is with the nan (not a number) from the missing data.

if you have a df like this:

data = [[1,2,3,4],[3,4,5,6],[np.nan,1,2,4]]
df = pd.DataFrame(np.array(data).transpose())

and create a list with the sums (like the way you are doing):

the last item would be a nan data:

[10.0, 18.0, nan]

And matplotlib wont plot it:

Possible solution:

Try to modify your lines like this, so you wont have nan data in your list:

rgn1=list(datainput['Allegany'].dropna())

Or you can simplify your code like this:

tc =  datainput.sum().values

In that last line of code, the pandas df will perform a sum in all columns and handle with the missing data.

Filipe
  • 169
  • 5