Issue
I have a value_count().sort_index() based on the colum 'categorynumber'of .csv file on the canton of bern
bern['categorynumber'].value_counts().sort_index()
the result is: lef| right :---| ----: 1.1 | 781 1.2 | 185 1.3 | 319 1.4 | 79 1.5 |170 1.6 | 3 1.7 | 20 2.1 |199 2.2 |856 2.3 | 63 2.4 |504 3.1 |139 3.2 |289 3.3 | 21 4.1 |366 4.2 | 276 4.3 |41 4.4 | 49 4.5 | 120 4.6 | 2285 4.7 | 478 5.1 | 65 5.2 | 137 5.3 | 75 5.4 | 46 Name: categorynumber, dtype: int64
now I would like to
create a bargraph but
df.plot (x = 'categorynumber', y = amount, kind = 'bar') does not seem to function as I have not defined the right (in the column) calculations as 'amount' so how do I do that?
create a table and bars (graph) based on the sum of 1.1-1.7; 2.1-2.4; 3.1-3.3; 4.1-4.7; 5.1-5.4 is that possible? if yes, how?
Solution
create a bargraph but
df.plot (x = 'categorynumber', y = amount, kind = 'bar') does not seem to function as I have not defined the right (in the column) calculations as 'amount' so how do I do that?
Apparently the plot
function knows better what to plot than you do, so just leave that to it and only specify kind:
s.plot(kind='bar')
(I named your value_count().sort_index() s
instead of df
because it's a Series, not a DataFrame.)
- create a table and bars (graph) based on the sum of 1.1-1.7; 2.1-2.4; 3.1-3.3; 4.1-4.7; 5.1-5.4 is that possible? if yes, how?
In your case, where the object is to be split by the integer part of the index, it's quite easy:
t = s.groupby(int).sum()
t.plot(kind='bar')
Answered By - Armali
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.