IconResources
Conduct analysis

Sort data

Organize your data by ordering rows based on a column, either alphabetically or numerically.

Example Data

Follow along with right out of the box example data. Copy following data in the information request of the agent you are working in.



Sorting data helps you see patterns. You might want to sort transactions by amount to find the largest transactions, or alphabetically by country to group entities. Sorting is a fast way to get insights: Who’s at the top? What comes first? Sorting doesn’t filter or delete — it simply rearranges the data to make it easier to read.

In this section, you’ll learn how to sort rows by any column — alphabetically, numerically, or by date.

Sort by a number column (ascending or descending)

Excel

In Excel, you click a column header and choose “Sort A to Z” or “Sort Z to A” for numbers or text.

t0 Prompt

Sort the table by amount

Show me the largest transactions first

Order rows by amount descending

Code

The python code looks as follows:

transactions["Amount"] = pd.to_numeric(transactions["Amount"])
sorted_data = transactions.sort_values("Amount", ascending=False)
sorted_data

Sort alphabetically

Excel

In Excel, you sort text columns from A to Z or Z to A — for example, sorting by country name.

t0 Prompt

Sort by buyer country

Order alphabetically by seller

Sort from A to Z by company

Code

The python code looks as follows:

sorted_data = transactions.sort_values("Buyer Country", ascending=True)
sorted_data

Sort by date

Excel

In Excel, you sort by date column to move from oldest to newest or vice versa.

t0 Prompt

Sort the transactions by date

Show the most recent rows first

Order table by date descending

Code

The python code looks as follows:

transactions["Date"] = pd.to_datetime(transactions["Date"])
sorted_data = transactions.sort_values("Date", ascending=False)
sorted_data
FunctionDescription
sort_values("Column")Sorts rows by values in a column
ascending=True , ascending=FalseSets sort order (True = A–Z, False = Z–A)
pd.to_numeric() / pd.to_datetime()Needed to sort numbers and dates correctly

On this page