From the course: Python for Data Visualization (2019)

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Convert pandas DataFrames to NumPy arrays or dictionaries

Convert pandas DataFrames to NumPy arrays or dictionaries

From the course: Python for Data Visualization (2019)

Convert pandas DataFrames to NumPy arrays or dictionaries

- [Instructor] When working with Pandas DataFrames you'll oftentimes find you want to convert them to NumPy arrays or Python dictionaries. The reason why is because certain libraries prefer NumPy arrays or Python dictionaries as inputs to their methods as opposed to Pandas DataFrames. In this video, we'll work with the car loan dataset again and we're going to look at the first five rows. There are two ways to convert Pandas DataFrames to NumPy arrays. The first approach is to use the two underscore NumPy method and what this outputs is a NumPy array. The second approach is to use the values attribute and this also produces a NumPy array. I should note that either of these approaches works just as well as the other. You can also convert Pandas DataFrames to Python dictionaries. You can do this by using the two underscore dict method and the reason why you'd want to do this versus convert your Pandas DataFrame to a NumPy array is oftentimes you're interested in…

Contents