Convert data frame pandas to array

0

I have a data that, from .txt, converted to a Dataframe (DF) with pandas. For the various activities that I realized it is very convenient that it be a DF.

There is only one column with values besides the index.

Now, I would like to convert DF to an array.

How can I do this?

    
asked by anonymous 03.09.2018 / 02:42

1 answer

3

Klel, in this case you can use the function:

' pandas.DataFrame.values '

Here is the usage example:

import pandas as pd
df = pd.DataFrame({'idade':    [ 3,  29],
                   'peso': [94, 170]})
vetor = df.values

To pass the entire DF to an array.

Or directly assign a single column to an array.

import pandas as pd
df = pd.DataFrame({'idade':    [ 3,  29],
                   'peso': [94, 170]})
vetor = df['idade'].values

On the last line just put the desired column.

Follow the Link for the documentation.

Example with 1 column

import pandas as pd
df = pd.DataFrame({'idade':[ 3,29,13,15,16,14,12]})
vetor = df.values
    
03.09.2018 / 13:44