Python uses xlrd, pandas packet data is read from Excel

# pip install xlrd

import xlrd
read_from_xls DEF (filepath, index_col_list): 
#filepath: read file path, for example: filepath = r'D: /Python_workspace/Felix_test/motion_test/running_7_29_21time_amsckg_getmRealAcc_S_pre.xlsx '
  # index_col_list: read column index list, such as the first and second three, four as: [1,2,3,4]
    Set # GBK encoding 
xlrd.Book.encoding = "GBK"
RB = xlrd.open_workbook (filepath)
#Print (RB)

Sheet = rb.sheet_by_index (0) represents a Sheet Excel # of
nrows = sheet.nrows
data_tmp_x = [ ], for example, data # x, y, z coordinate data
data_tmp_y = []
data_tmp_z = []
for index_col in index_col_list: # index_col sequentially selects the first column
for I in Range (nrows):
tt = I + tt. 1 reads the first line # removing the first row of column names
IF TT> = nrows:
BREAK
the else:
tmp = a float (sheet.cell_value (TT, index_col)) # read data contents of the first few lines of the columns of the
IF index_col == 2:
data_tmp_x. the append (tmp)
elif index_col ==. 3:
data_tmp_y.append (tmp)
elif index_col ==. 4:
data_tmp_z.append (tmp)
data_tmp np.mat = ([data_tmp_x, data_tmp_y, data_tmp_z])
it returns data_tmp

# pandas read using Excel
# filepath: XLSX file pathname
import pandas as PD
Data = pd.read_excel (filepath)
province_name = Data [ 'Province']. values.tolist () # Province name of a column, resulting in a list
province_people = data [ 'count'] . values.tolist ()
## are welcome to correct errors, but also to improve the exchange of

Guess you like

Origin www.cnblogs.com/qi-yuan-008/p/11672761.html