Computer scienceData scienceInstrumentsPandasData analysis with pandas

Reshaping and Pivot Tables

Pivot wine

Report a typo

Take a look at the wine dataset:

df.head()

Output:

+----+--------------------+-----------+----------+
|    | variety            | country   |   points |
|----+--------------------+-----------+----------|
|  0 | Pinot Noir         | US        |       87 |
|  1 | Cabernet Sauvignon | US        |       87 |
|  2 | Red Blend          | US        |       87 |
|  3 | White Blend Italy  | Italy     |       87 |
|  4 | Merlot             | US        |       87 |
+----+--------------------+-----------+----------+

Which answer/answers will pivot that table to make it look like this:

+--------------------------+--------------+-------------+----------+----------+--------------+---------------+----------+
|                  country |    Argentina |   Australia |   Canada |   France |        Italy |         Spain |       US |
|                  variety |              |             |          |          |              |               |          |
|--------------------------+--------------+-------------+----------+----------+--------------+---------------+----------|
| Bordeaux-style Red Blend | 89.7468      |     89.25   |  90.4667 |  87.7738 | 89.5         |  87.1667      |  89.7903 |
| Cabemet Sauvignon        | 86.445       |     89.8065 |  88      |  86.4    | 89.2759      |  87.4048      |  89.6784 |
| Chardonnay               | 85.1765      |     88.1019 |  88.8571 |  89.913  | 88.5364      |  85.2703      |  89.5169 |
| Merlot                   | 85.1471      |     86.8571 |  88      |  86.5821 | 89.1489      |   8.44545e+07 |  88.1451 |
| PinotNoir                | 86.1176      |     87.2917 |  89.0714 |  89.8983 | 86           |  87           |  90.4293 |
| Red Blend                | 88.3971      |     87.85   |  90.6    |  88.2615 | 88.8748      | 988.184       | 988.457  |
| Rosé                     |  8.41667e+07 |     86.7778 |  86.5    |  87.4161 | 87.25        |   8.45566e+07 |  87.6824 |
| Sauvignon Blanc          | 84.6346      |     86.7368 |  88.75   |  88.9302 |  9.87611e+08 |   8.44375e+07 |  88.4619 |
| Syrah                    | 86.1087      |     91.7333 |  91      |  90.4727 | 88.8367      |  88.2963      |  90.4172 |
| White Blend              | 84.7667      |     86.3333 |  87.8    |  87.4192 | 88.2441      |  86.2076      |  87.9098 |
+--------------------------+--------------+-------------+----------+----------+--------------+---------------+----------+

Points are aggregated with mean function.

Select one or more options from the list
___

Create a free account to access the full topic