How to get read excel data into an array with python

前端 未结 4 880
误落风尘
误落风尘 2021-01-05 10:06

In the lab that I work in, we process a lot of data produced by a 96 well plate reader. I\'m trying to write a script that will perform a few calculations and output a bar g

相关标签:
4条回答
  • 2021-01-05 10:15

    This task is super easy in Pandas these days.

    import pandas as pd

    df = pd.read_excel('file_name_here.xlsx', sheet_name='Sheet1')

    or

    df = pd.read_csv('file_name_here.csv')

    This returns a pandas.DataFrame object which is very powerful for performing operations by column, row, over an entire df, or over individual items with iterrows. Not to mention slicing in different ways.

    0 讨论(0)
  • 2021-01-05 10:25

    There is awesome xlrd package with quick start example here. You can just google it to find code snippets. I have never used panda's read_excel function, but xlrd covers all my needs, and can offer even more, I believe.

    0 讨论(0)
  • 2021-01-05 10:26

    I'm not exactly sure what you mean when you say array, but if you mean into a matrix, might you be looking for:

    import pandas as pd
    df = pd.read_excel([path here])
    df.as_matrix()
    

    This returns a numpy.ndarray type.

    0 讨论(0)
  • 2021-01-05 10:30

    You could also try it with my wrapper library, which uses xlrd as well:

    import pyexcel as pe     # pip install pyexcel
    import pyexcel.ext.xls   # pip install pyexcel-xls
    your_matrix = pe.get_array(file_name=path_here) # done
    
    0 讨论(0)
提交回复
热议问题