Computer scienceData scienceInstrumentsPandasData preprocessing with pandas

Sorting Data in Pandas

Double trouble

Report a typo

Sort this sample DataFrame by quantity and vendor_code columns in descending order. Then print the result.

+----+----------+---------+------------+---------------+
|    | type     |   price |   quantity |   vendor_code |
|----+----------+---------+------------+---------------|
|  0 | PC       |     450 |          5 |           135 |
|  1 | monitor  |     150 |          2 |           960 |
|  2 | printer  |     175 |         10 |           004 |
|  3 | notebook |     600 |         15 |           420 |
|  4 | PC       |     500 |          5 |           114 |
+----+----------+---------+------------+---------------+
Write a program in Python 3
import pandas as pd

goods = {
"type": ['PC', 'monitor', 'printer', 'notebook', 'PC'],
"price": [450, 150, 175, 600, 500],
"quantity": [5, 2, 10, 15, 5],
"vendor_code": ['135', '960', '004', '420', '114'],
}
df = pd.DataFrame(goods)

# your code here
print(...)
___

Create a free account to access the full topic