Skip to content

Commit

Permalink
Cleaned up sorting bits
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire committed Feb 26, 2022
1 parent 9ea3f2e commit dea0b51
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ columns
filters
merge
totals
sort_values/index
sorting
groupby/index
compute
remix/index
Expand Down
14 changes: 6 additions & 8 deletions docs/src/sort_values/index.md → docs/src/sorting.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ kernelspec:
name: python3
---

```{include} ../_templates/nav.html
```{include} ./_templates/nav.html
```

# Sorting

Another simple but common technique for analyzing data is sorting.

What were the ten biggest contributions? We can find the answer by using the [sort_values] method to rearrange our list using the amount field.
What were the ten biggest contributions? We can find the answer by using the [`sort_values`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.sort_values.html) method to rearrange our list using the `amount` field.

```{code-cell}
:tags: [hide-cell]
Expand All @@ -42,28 +42,26 @@ Note that returns the DataFrame resorted in ascending order from lowest to highe

To answer our question you'll need to reverse that, so that values are sorted in descending order from biggest to smallest.

It's a little tricky at first, but here's how to do it with sort_values.
It's a little tricky at first, but here's how to do it with `sort_values`.

```{code-cell}
merged_prop.sort_values("amount", ascending=False)
```

You can limit the result to the top five by chaining the head method at the end.
You can limit the result to the top five by chaining the `head` method at the end.

```{code-cell}
merged_prop.sort_values("amount", ascending=False).head()
```

We can now use the new variable to rank the five biggest supporting contributions by using sort_values again.
We can now use the `support` DataFrame to rank the five biggest supporting contributions by using `sort_values` again.

```{code-cell}
support.sort_values("amount", ascending=False).head()
```

And now how about the opposition.
And now how about the opposition with the `oppose` DataFrame.

```{code-cell}
oppose.sort_values("amount", ascending=False).head()
```

[sort_values]: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.sort_values.html

0 comments on commit dea0b51

Please sign in to comment.