Computer scienceData scienceInstrumentsPandasData preprocessing with pandas

Sorting Data in Pandas

Peng-sort

Report a typo

You are given a part of the palmer penguins dataset:

+----+-----------+----------+---------------+
|    | species   | island   |   body_mass_g |
|----+-----------+----------+---------------|
|  0 | Adelie    | Dream    |          3500 |
|  1 | Chinstrap | Dream    |          3500 |
|  2 | Gentoo    | Biscoe   |          5100 |
|  3 | Adelie    | Biscoe   |          3400 |
|  4 | Gentoo    | Biscoe   |          4950 |
|  5 | Chinstrap | Dream    |          3250 |
+----+-----------+----------+---------------+

First, sort the dataset by species and body_mass_g columns ascending. And then print the result.

Write a program in Python 3
import pandas as pd

penguins_dict = {'species':
{0: 'Adelie', 1: 'Chinstrap', 2: 'Gentoo',
3: 'Adelie', 4: 'Gentoo', 5: 'Chinstrap'},
'island':
{0: 'Dream', 1: 'Dream', 2: 'Biscoe', 3: 'Biscoe',
4: 'Biscoe', 5: 'Dream'},
'body_mass_g': {0: 3500, 1: 3500, 2: 5100,
3: 3400, 4: 4950, 5: 3250}}
penguins_example = pd.DataFrame(penguins_dict)

# your code here
print(...)
___

Create a free account to access the full topic