Python3 reading an Excel file extracts only the values of certain columns in some rows

Source: Internet
Author: User

Today, a classmate gave me an Excel file, asked to read some rows, some columns, and then I tried to do a demo, here to share out, hoping to help everyone:

First install XLRD:

PIP3 Install XLRD
And then the code:


Import NumPy as NP
import xlrd
data = Xlrd.open_workbook (' lifetable_16.xlsx ')
table = data.sheets () [0] #
Print (table)
# nrows = table.nrows #行数
# ncols = table.ncols #列数
# c1=arange (0,nrows,1)
# Print (c1

start=6  #开始的行
end=106  #结束的行

rows=end-start


list_values=[] for
x in range ( Start,end):
    values=[]
    row =table.row_values (x) for
    I in range (1,7):
        # Print (value)
        Values.append (Row[i])
    list_values.append (values)
# Print (list_values)
Datamatrix=np.array (list_ Values)
print (Datamatrix)


Reference Documents

[The 1].numpy array and the list in Python are transformed from one to the other. https://blog.csdn.net/baiyu9821179/article/details/53365476

[2]. python-stores the data in Excel inside the matrix. https://blog.csdn.net/cmdtth/article/details/52278049

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.