<commit_before>#from openpyxl import load_workbook
from openpyxl import load_workbook

class Excel(object):

    def __init__(self, file_path = 'data/scg/test.xlsx'):
        # Load in the workbook
        wb = load_workbook(file_path)

        # Get sheet names
        print(wb.get_sheet_names())  # [u'hw_record', u'Sheet1']

        # Get a sheet by name
        self.worksheet = wb.get_sheet_by_name('hw_record')

    def get_scg_record(self, index):
        '''
        get the id, scg_content, and scg truth for record at index
        :param index: row index in the excel sheet
        :return: (id, scg, scg_truth)
        '''
        if index < 2 or index > self.get_row_number():
            raise ValueError(" index is out of range !!!")
        (idx1, idx2, idx3) = ('A' + str(index), 'B' + str(index), 'C' + str(index))
        return self.worksheet[idx1].value, self.worksheet[idx2].value, self.worksheet[idx3].value

    def get_row_number(self):
        return len(self.worksheet['A'])
<commit_msg>Excel class for excel file handling. provide function read row by row index<commit_after>#from openpyxl import load_workbook
from openpyxl import load_workbook
import xlrd

class Excel(object):

    def __init__(self, file_path = 'data/scg/test.xlsx'):
        # Load in the workbook
        wb = xlrd.open_workbook(file_path, on_demand = True)

        # Get sheet names
        #print(wb.get_sheet_names())  # [u'hw_record', u'Sheet1']

        # Get a sheet by name
        #self.worksheet = wb.get_sheet_by_name('hw_record')
        self.worksheet = wb.sheet_by_index(0)

    def get_scg_record(self, index):
        '''
        get the id, scg_content, and scg truth for record at index
        :param index: row index in the excel sheet
        :return: (id, scg, scg_truth)
        '''
        if index < 1 or index > self.get_row_number():
            print 'index: ', index
            raise ValueError(" index is out of range !!!")
        row = index

        return int(self.worksheet.cell_value(row, 0)), self.worksheet.cell_value(row, 1), self.worksheet.cell_value(row, 2)

    def get_row_number(self):
        return self.worksheet.nrows

{'fraction_non_alphanumeric': 0.11065006915629322, 'fraction_numerical': 0.006454587367450438, 'mean_word_length': 2.7157534246575343, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4195197', 'n_tokens_mistral': 726, 'n_tokens_neox': 700, 'n_words': 195}