Python for Data Analysis: A Step-By-Step Guide to Master the Basics of Data Science and Analysis in Python Using Pandas, Numpy And Ipython (Data Science Mastery Book 2) by Park Andrew

Python for Data Analysis: A Step-By-Step Guide to Master the Basics of Data Science and Analysis in Python Using Pandas, Numpy And Ipython (Data Science Mastery Book 2) by Park Andrew

Author:Park, Andrew [Park, Andrew]
Language: eng
Format: epub
Published: 2020-07-05T16:00:00+00:00


Chapter 6

Pandas

Pandas are built on NumPy and they are meant to be used together. This makes it extremely easy to extract arrays from the data frames. Once these arrays are extracted, they can be turned into data frames themselves. Let’s take a look at an example:

In: import pandas as pd

import numpy as np

marketing_filename = 'regression-datasets-marketing.csv'

marketing = pd.read_csv(marketing _filename, header=None)

In this phase, we are uploading data to a data frame. Next, we’re going to use the “values” method to extract an array that is of the same type as those contained inside the data frame.

In: marketing_array = marketing.values

marketing_array.dtype

Out: dtype('float64')

We can see that we have a float type array. You can anticipate the type of the array by first using the “dtype” method. This will establish which types are being used by the specified data frame object. Do this before extracting the array. This is how this operation would look:

In: marketing.dtypes

Out: 0float64

1int64

2float64

3int64

4float64

5float64

6float64

7float64

8int64

9int64

10int64

11float64

12float64

13float64

dtype: object



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.