This notebook is an exercise in the Pandas course. You can reference the tutorial at this link.


Introduction

The first step in most data analytics projects is reading the data file. In this exercise, you'll create Series and DataFrame objects, both by hand and by reading data files.

Run the code cell below to load libraries you will need (including code to check your answers).

Exercises

1.

In the cell below, create a DataFrame fruits that looks like this:

2.

Create a dataframe fruit_sales that matches the diagram below:

3.

Create a variable ingredients with a Series that looks like:

Flour     4 cups
Milk       1 cup
Eggs     2 large
Spam       1 can
Name: Dinner, dtype: object

4.

Read the following csv dataset of wine reviews into a DataFrame called reviews:

The filepath to the csv file is ../input/wine-reviews/winemag-data_first150k.csv. The first few lines look like:

,country,description,designation,points,price,province,region_1,region_2,variety,winery
0,US,"This tremendous 100% varietal wine[...]",Martha's Vineyard,96,235.0,California,Napa Valley,Napa,Cabernet Sauvignon,Heitz
1,Spain,"Ripe aromas of fig, blackberry and[...]",Carodorum Selección Especial Reserva,96,110.0,Northern Spain,Toro,,Tinta de Toro,Bodega Carmen Rodríguez

5.

Run the cell below to create and display a DataFrame called animals:

In the cell below, write code to save this DataFrame to disk as a csv file with the name cows_and_goats.csv.

Keep going

Move on to learn about indexing, selecting and assigning.


Have questions or comments? Visit the Learn Discussion forum to chat with other Learners.