Exercise

NumPy and pandas working together

Pandas depends upon and interoperates with NumPy, the Python library for fast numeric array computations. For example, you can use the
DataFrame attribute .values to represent a DataFrame df as a NumPy
array. You can also pass pandas data structures to NumPy methods. In this exercise, we have imported pandas as pd and loaded world population data every 10 years since 1960 into the DataFrame df. This dataset was derived from the one used in the previous exercise.

Your job is to extract the values and store them in an array using the attribute .values. You'll then use those values
as input into the NumPy np.log10() method to compute the base 10 logarithm of the population values.
Finally, you will pass the entire pandas DataFrame into the same NumPy np.log10() method and compare the results.

Instructions

100 XP

Import numpy using the standard alias np.

Assign the numerical values in the DataFrame df to an array np_vals using the attribute values.

Pass np_vals into the NumPy method log10() and store the results in np_vals_log10.

Pass the entire df DataFrame into the NumPy method log10() and store the results in df_log10.

Call print() and type() on both df_vals_log10 and df_log10, and compare. This has been done for you.