How to convert the dataframe to array in python?

12,389

you can use as_matrix function.

import pandas as pd

Location = r'C:\temp\test.xlsx'
data = pd.read_excel(Location, '4bar', header=0, parse_cols=0)
numpy_data = data.as_matrix()
Share:
12,389
LF. Sun
Author by

LF. Sun

I am an electrical engineer in Germany. I am a beginner for python programming. I would like to use python to analyse/evaluate my measurement data and create reports automatically.

Updated on June 05, 2022

Comments

  • LF. Sun
    LF. Sun almost 2 years

    I have read data from excel like the followings:

    import numpy as np
    import pandas as pd
    
    Location = r'C:\temp\test.xlsx'
    data = pd.read_excel(Location, '4bar',     header=0,     parse_cols=0)
    
    data
    Out[80]: 
                 10V        11V
    0     -60.531006 -31.539307
    1      -2.547607 -30.776367
    2      58.487549  48.569336
    3      72.220459  74.509277
    4      64.591064  74.509277
    5      54.672852  60.013428
    

    I want to put the column '10V' and '11V' into two arrays. In order to process the data with filter coefficients. But I don't know how to copy column to array or how to access/operate the element directly in DataFrame?

    Can anyone give me a hint? Thank you.

  • LF. Sun
    LF. Sun about 8 years
    Thank you very much for the solution. It is what I wanted!
  • LF. Sun
    LF. Sun about 8 years
    It's done. It was my first question. Now I understand the process here;-)