Sectie 3. Hoofdstuk 4
single
Sorting Data
Veeg om het menu te tonen
We need sorting for ease of work.
We can sort our data in 2 ways: ascending sorting and descending sorting.
To perform the ascending sorting, use the following code:
DataFrame.sort_values(by = 'column_name', inplace = True)
If we want to perform descending, we have to turn off the ascending parameter.
DataFrame.sort_values(by = 'column_name', inplace = True, ascending = False)
If the parameter inplace is set to
True(inplace = True), it will perform the operation inplace. Modify the original DataFrame itself. The return type isNone.
Taak
Veeg om te beginnen met coderen
Now we are going to practice sorting. We will sort 2 different DataFrame columns using ascending and descending sorting.
- Import the
pandasusing thepdalias. - Perform an ascending sorting by the
'price'column. - Perform a descending sorting by the
'user_id'column.
Oplossing
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 3. Hoofdstuk 4
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.