Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import xlrd # pip install xlrd==1.2.0
- import pandas as pd
- data = []
- path = 'files'
- for nfile in os.listdir(path):
- book = xlrd.open_workbook(path + '\\' + nfile) # открытие книги
- sheet = book.sheet_by_index(0) # получение первой вкладки
- rows = sheet.nrows # число строк
- cols = sheet.ncols # число столбцов
- # print(cols, '\t', rows)
- row_start = 7 # начать со строки номер восемь (индексация с нуля)
- row_finish = rows # закончить на последней строке
- col_start = 3 # начать со столбца номер четыре (индексация с нуля)
- col_finish = 5 # закончить на столбце номер шесть (индексация с нуля)
- temp = [nfile]
- for r in range(row_start, row_finish):
- for c in range(col_start, col_finish):
- cell_xls = sheet.cell_value(rowx=r, colx=c)
- if cell_xls == 'заголовок':
- break
- else:
- temp.append(cell_xls)
- data.append(temp)
- # print(data)
- df = pd.DataFrame(data)
- df
Advertisement
Add Comment
Please, Sign In to add comment