Personal selection

Report a typo

Given the example dataframe, select artist, song columns and the last three rows only. Print the result:

chart2020.head()

Output:

+----+--------------+-----------------+-----------+-----------+-----------+-----------+-----------+----------------+
|    | artist       | song            |   peak_us |   peak_uk |   peak_de |   peak_fr |   peak_ca |   result_place |
|----+--------------+-----------------+-----------+-----------+-----------+-----------+-----------+----------------|
|  0 | The Weeknd   | Blinding Lights |         1 |         1 |         1 |         1 |         1 |              1 |
|  1 | Dua Lipa     | Don't Start Now |         2 |         3 |        10 |        12 |         3 |              2 |
|  2 | Roddy Ricch  | The Box         |         1 |         2 |        12 |         7 |         1 |              3 |
|  3 | Post Malone  | Circles         |         1 |        19 |        37 |        77 |         3 |              4 |
|  4 | Harry Styles | Adore You       |         6 |         7 |        83 |       126 |        10 |              5 |
+----+--------------+-----------------+-----------+-----------+-----------+-----------+-----------+----------------+

Notes:

  • dataframe contains more than 5 rows
  • select columns in the specified order
  • do not reset the indexes, they should remain
Write a program in Python 3
import pandas as pd

chart_dict = {"artist": {0: "The Weeknd", 1: "Dua Lipa", 2: "Roddy Ricch", 3: "Post Malone", 4: "Harry Styles", 5: "Tones And I", 6: "Future & Drake", 7: "Lewis Capaldi"}, "song": {0: "Blinding Lights", 1: "Don't Start Now", 2: "The Box", 3: "Circles", 4: "Adore You", 5: "Dance Monkey", 6: "Life Is Good", 7: "Before You Go"}, "peak_us": {0: 1, 1: 2, 2: 1, 3: 1, 4: 6, 5: 4, 6: 2, 7: 9}, "peak_uk": {0: "1", 1: "3", 2: "2", 3: "19", 4: "7", 5: "-", 6: "3", 7: "1"}, "peak_de": {0: "1", 1: "10", 2: "12", 3: "37", 4: "83", 5: "1", 6: "8", 7: "42"}, "peak_fr": {0: "1", 1: "12", 2: "7", 3: "77", 4: "126", 5: "3", 6: "33", 7: "49"}, "peak_ca": {0: 1, 1: 3, 2: 1, 3: 3, 4: 10, 5: 1, 6: 3, 7: 16}, "result_place": {0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 8}}

chart2020 = pd.DataFrame(chart_dict)

# your code here
print(...)
___

Create a free account to access the full topic