Assignment 3: pandas-practice-assignment Q1

I tried to use the shape method to retrieve the num_countries contained in the countries_df but I am getting a fail response. Below are different codes I tried but still getting the same fail response:

num_countries = countries_df[‘location’].shape
num_countries = countries_df[‘location’].size

.shape returns a tuple of arrays’ shape (length and breadth)
Since we only need the length here; we can do:

num_countries = countries_df['location'].shape[0]

The [0] would access the first element of the tuple which would be the length.

Or we can directly get the length with:

num_countries = len(countries_df)

Also, we don’t need to do access the 'location' column with countries_df['location'], as countries_dfwould be of the same length as well

1 Like