Pandas Series Sort
I have a Pandas dataframe called pd, and I extract the number of unique
values in one of the columns of this dataframe using the following
command:
b = df.groupby('Region').size()
b is a Pandas series object and looks like this:
b
Out[48]:
Region
0 8
1 25
11 1
2 41
3 23
4 15
5 35
6 24
7 27
8 50
9 55
N 10
I am trying to plot a barchart of this series, however, I would like to
sort it first based on the first column (because of that 11 between 1 and
2), which will be the x axis labels. I tried passing the sort command, but
it sorts the series based on the values in the second column:
b.sort()
b
Out[54]:
Region
11 1
0 8
N 10
4 15
3 23
6 24
1 25
7 27
5 35
2 41
8 50
9 55
Well, is there a way to sort this series based on the first column?
No comments:
Post a Comment