• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python xlrd.xldate_as_tuple函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中xlrd.xldate_as_tuple函数的典型用法代码示例。如果您正苦于以下问题:Python xldate_as_tuple函数的具体用法?Python xldate_as_tuple怎么用?Python xldate_as_tuple使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了xldate_as_tuple函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: parse_file

def parse_file(datafile):
    workbook = xlrd.open_workbook(datafile)
    sheet = workbook.sheet_by_index(0)
    
    second_column_values = sheet.col_values(1,1)
    
    min_value = min(second_column_values)
    max_value = max(second_column_values)
    avg_value = sum(second_column_values) / len(second_column_values)
    
    min_pos = second_column_values.index(min_value)
    max_pos = second_column_values.index(max_value)
    
    
    min_value_exceltime = sheet.cell_value(min_pos+1,0)
    max_value_exceltime = sheet.cell_value(max_pos+1,0)
    
    min_value_time = xlrd.xldate_as_tuple(min_value_exceltime, 0)
    max_value_time = xlrd.xldate_as_tuple(max_value_exceltime, 0)    

    ### example on how you can get the data
    #sheet_data = [[sheet.cell_value(r, col) for col in range(sheet.ncols)] for r in range(sheet.nrows)]

    ### other useful methods:
    # print "\nROWS, COLUMNS, and CELLS:"
    # print "Number of rows in the sheet:", 
    # print sheet.nrows
    # print "Type of data in cell (row 3, col 2):", 
    # print sheet.cell_type(3, 2)
    # print "Value in cell (row 3, col 2):", 
    # print sheet.cell_value(3, 2)
    # print "Get a slice of values in column 3, from rows 1-3:"
    # print sheet.col_values(3, start_rowx=1, end_rowx=4)

    # print "\nDATES:"
    # print "Type of data in cell (row 1, col 0):", 
    # print sheet.cell_type(1, 0)
    # exceltime = sheet.cell_value(1, 0)
    # print "Time in Excel format:",
    # print exceltime
    # print "Convert time to a Python datetime tuple, from the Excel float:",
    # print xlrd.xldate_as_tuple(exceltime, 0)
    
    
    """data = {
            'maxtime': (0, 0, 0, 0, 0, 0),
            'maxvalue': 0,
            'mintime': (0, 0, 0, 0, 0, 0),
            'minvalue': 0,
            'avgcoast': 0
    }"""
    
    data = {}
    data['maxtime'] = max_value_time
    data['maxvalue'] = max_value
    data['mintime'] = min_value_time
    data['minvalue'] = min_value
    data['avgcoast'] = avg_value
    
    return data
开发者ID:MaiBui,项目名称:Data-Wrangling-with-MongoDB,代码行数:60,代码来源:readxls.py


示例2: parse_file

def parse_file(datafile):
    workbook = xlrd.open_workbook(datafile)
    sheet = workbook.sheet_by_index(0)
    coast = 1
    date = 0
    sum = 0
    val = 0

    data = {
            'maxtime': (0, 0, 0, 0, 0, 0),
            'maxvalue': -1,
            'mintime': (0, 0, 0, 0, 0, 0),
            'minvalue': 9999999,
            'avgcoast': 0
    }
    for row in range(1, sheet.nrows):
        val = sheet.cell_value(row, coast)
        sum += val

        #find min
        if val < data['minvalue']:
            data['minvalue'] = val
            data['mintime'] = xlrd.xldate_as_tuple(sheet.cell_value(row, date), 0)
    
        #find max
        if val > data['maxvalue']:
            data['maxvalue'] = val
            data['maxtime'] = xlrd.xldate_as_tuple(sheet.cell_value(row, date), 0)

    data['avgcoast'] = sum / (sheet.nrows - 1)

    return data
开发者ID:Bryan3538,项目名称:Data-Wrangling,代码行数:32,代码来源:excel_exercise.py


示例3: parse_xfile

def parse_xfile(DataFile):
    workbook=xlrd.open_workbook(DataFile)
    sheet=workbook.sheet_by_index(0)
    cv=sheet.col_values(1,start_rowx=1,end_rowx=None)
    avgcoast=sum(cv)/len(cv)
    
    maxvalue=max(cv)
    minvalue=min(cv)
    maxpos=cv.index(maxvalue)+1
    minpos=cv.index(minvalue)+1
    
    maxtime=sheet.cell_value(maxpos,0)
    mintime=sheet.cell_value(minpos,0)
    
    realmaxtime=xlrd.xldate_as_tuple(maxtime,0)
    realmintime=xlrd.xldate_as_tuple(mintime,0)
    
    data={
        'maxvalue': maxvalue,
        'realmaxtime': realmaxtime,
        'minvalue':minvalue,
        'realmintime':realmintime,
        'avgcoast':avgcoast
    }
    return data
开发者ID:shrutisingh15,项目名称:Data_Wrangling_With_MongoDB,代码行数:25,代码来源:DataWrangling_lesson1_lesson2_Practice_Notebook.py


示例4: read_xl_doc

def read_xl_doc():
    # We want the data in the first columns of the various sheets.
    alldata = []
    print_data = []
    import xlrd
    with xlrd.open_workbook('SchwartzSmithMultiMarketExampleData.xls') as wb:
        for sheet_name in wb.sheet_names():
            sheet = wb.sheet_by_name(sheet_name)
            month_col_title = sheet.cell_value(1, 0)
            assert month_col_title == 'Month', month_col_title
            from xlrd import xldate_as_tuple
            months = [datetime.datetime(*xldate_as_tuple(c.value, wb.datemode)) for c in sheet.col_slice(0)[2:]]

            fo_col_title = sheet.cell_value(1, 1)
            assert fo_col_title == 'F0', fo_col_title
            futures = [c.value for c in sheet.col_slice(1)[2:]]

            iv_col_title = sheet.cell_value(1, 2)
            assert iv_col_title == "Vol", iv_col_title
            impvols = [c.value for c in sheet.col_slice(2)[2:]]

            def param(params, key, row, col):
                v = sheet.cell_value(row, col)
                if isinstance(key, basestring) and key.lower()[-4:] == 'date':
                    v = datetime.datetime(*xldate_as_tuple(v, wb.datemode))
                params[key] = v

            observation_date = datetime.datetime(*xldate_as_tuple(sheet.cell_value(21, 15), wb.datemode))

            seasonal_factors = [1] * 12
            for month_int in range(12):
                param(seasonal_factors, month_int, month_int+24, 14)

            params = {}
            param(params, 'kappa', 18, 13)
            param(params, 'mue', 18, 14)
            param(params, 'sigmax', 18, 15)
            param(params, 'sigmae', 18, 16)
            param(params, 'lambdae', 18, 17)
            param(params, 'lambdax', 18, 18)
            param(params, 'pxe', 18, 19)
            param(params, 'x0', 18, 20)
            param(params, 'e0', 18, 21)

            alldata.append([observation_date, months, futures, impvols, seasonal_factors, params])
            idata = {
                'observation_date': "%04d-%02d-%02d" % (observation_date.year, observation_date.month, observation_date.day),
                'months': ["%04d-%02d-%02d" % (m.year, m.month, m.day) for m in months],
                'futures': [i for i in futures],
                'impvols': [i for i in impvols]
            }
            print_data.append(idata)

    import json
    print("import datetime")
    print("from numpy import array")
    print()
    print(json.dumps(print_data, indent=4))

    return alldata
开发者ID:nik0p0l,项目名称:pycommodities,代码行数:60,代码来源:schwartzsmithtest.py


示例5: parse_file

def parse_file(df):
    workbook = xlrd.open_workbook(df)
    sheet = workbook.sheet_by_index(0)
    #all values in sheet
    #sheet_data = [[sheet.cell_value(r, col)
                    # for col in range(sheet.ncols)]
                        #for r in range(sheet.nrows)]
                            
    coast = sheet.col_values(1, start_rowx=1, end_rowx=7297) #or end_rox=None for all values
    
    maxval = max(coast)
    minval = min(coast)
    
    maxpos = coast.index(maxval)+1
    minpos = coast.index(minval)+1
    
    maxtime = sheet.cell_value(maxpos,0)
    realmaxtime = xlrd.xldate_as_tuple(maxtime,0)
    mintime = sheet.cell_value(minpos,0)
    realmintime = xlrd.xldate_as_tuple(mintime,0)
    
    avgcoast = float(sum(coast))/ len(coast)
    
    data = {
            'maxtime': realmaxtime,
            'maxvalue': maxval,
            'mintime': realmintime,
            'minvalue': minval, 
            'avgcoast': avgcoast
    }
    return data    
开发者ID:bpaul5,项目名称:Wrangle_OpenStreetMap_Data,代码行数:31,代码来源:Problem+Set+1.py


示例6: parse_file

def parse_file(datafile):
    workbook = xlrd.open_workbook(datafile)
    sheet = workbook.sheet_by_index(0)

    sheet_data = [[sheet.cell_value(r, col) for col in range(sheet.ncols)] for r in range(sheet.nrows)]
    
    data = {
            'maxtime': (0, 0, 0, 0, 0, 0),
            'maxvalue': 0,
            'mintime': (0, 0, 0, 0, 0, 0),
            'minvalue': 0,
            'avgcoast': 0
    }
        
    data['maxvalue'] = sheet_data[1][1]
    data['maxtime'] = xlrd.xldate_as_tuple(sheet_data[1][0], 0)
    data['minvalue'] = sheet_data[1][1]
    data['mintime'] = xlrd.xldate_as_tuple(sheet_data[1][0], 0)
    data['avgcoast'] += data['avgcoast'] + sheet_data[1][1] 

    for i in (range(2,sheet.nrows)):
        if (sheet_data[i][1]>data['maxvalue']):
            data['maxvalue'] = sheet_data[i][1]
            data['maxtime'] = xlrd.xldate_as_tuple(sheet_data[i][0], 0)
        if (sheet_data[i][1]<data['minvalue']):
            data['minvalue'] = sheet_data[i][1]
            data['mintime'] = xlrd.xldate_as_tuple(sheet_data[i][0], 0)
        data['avgcoast'] += sheet_data[i][1]
        #print data['avgcoast']
    data['avgcoast'] = data['avgcoast']/(sheet.nrows-1)
    return data
开发者ID:ximiki,项目名称:udacity_P3,代码行数:31,代码来源:DWM_L1_2_Reading+Excel+Files.py


示例7: create_event

def create_event(row_data, datemode):
    title, start_date, end_date, slug, topics, importance = row_data
    # we could bulk create the events for efficiency later if necessary

    start_date = datetime(*xldate_as_tuple(start_date, datemode))
    end_date = datetime(*xldate_as_tuple(end_date, datemode))
    ev, new = Event.objects.get_or_create(title=title.strip(),
                                          start_date=start_date,
                                          end_date=end_date,
                                          slug=slug.strip(),
                                          importance=importance)

    if not new:
        ev.start_date = start_date
        ev.end_date = end_date
        ev.title = title.strip()
        ev.importance = importance
            
    topics = topics.split(',')
    for topic in topics:
        topic = topic.strip()
        t, created = Topic.objects.get_or_create(name=topic)
        t.save()
        ev.topics.add(t)

    ev.save()
    
    db.close_connection()
开发者ID:Timewire,项目名称:timewire,代码行数:28,代码来源:views.py


示例8: parse_file

def parse_file(datafile):
    workbook = xlrd.open_workbook(datafile)
    sheet = workbook.sheet_by_index(0)

    ## get the data from sheet
    data = [[sheet.cell_value(r, col) 
                      for col in range(sheet.ncols)] 
                          for r in range(sheet.nrows)]
    
    print data
    cv = sheet.col_values(1, start_rowx=1, end_rowx=None)    
    
    maxval = max(cv)
    minval = min(cv)
    
    ## add +1 because our data (cv) was formed from 1 row, not from 0 row.
    maxpos = cv.index(maxval) + 1
    minpos = cv.index(minval) + 1
    
    ## get max and min time according to position of maxval and minval
    maxtime = sheet.cell_value(maxpos, 0)
    realmaxtime = xlrd.xldate_as_tuple(maxtime,0)
    mintime = sheet.cell_value(minpos, 0)
    realmintime = xlrd.xldate_as_tuple(mintime, 0)
    
    data = {
            'maxtime': realmaxtime,
            'maxvalue': maxval,
            'mintime': realmintime,
            'minvalue': minval,
            'avgcoast': numpy.mean(cv)
    }
    print data
开发者ID:DariaAlekseeva,项目名称:Data_Analyst_Udacity,代码行数:33,代码来源:Parsing_XLS_files.py


示例9: readExcel

def readExcel(inputFile):
    donation_ids = []
    fields = {"DonationDate":"date","Amount":"amount","DonationMode":"mode","ModeDescription":"mode_description","DonorEmail":"email_address","Name":"name","ContactNo":"contact_number","Address":"address"}
    order_of_fields = {}
    workbook = xlrd.open_workbook(inputFile)
    worksheet = workbook.sheet_by_index(0)
    num_rows = worksheet.nrows - 1 
    num_cells = worksheet.ncols - 1 
    curr_row = -1
    if num_cells > 0:
        curr_row += 1
        curr_cell = -1
        while curr_cell < num_cells:
            curr_cell += 1
            cell_value = worksheet.cell_value(curr_row, curr_cell)
            order_of_fields[cell_value] = curr_cell
    while curr_row < num_rows:
        row = []
        curr_row += 1
        row = worksheet.row(curr_row)
        print 'Row:', curr_row
        curr_cell = -1
        while curr_cell < num_cells:
            curr_cell += 1
            cell_type = worksheet.cell_type(curr_row, curr_cell)
            cell_value = worksheet.cell_value(curr_row, curr_cell)
            if(cell_type > 4 or cell_type == 0):
            	row.append(None)
            elif(cell_type == 3):
                year, month, day, hour, minute, second = xlrd.xldate_as_tuple(cell_value, workbook.datemode)
	        row.append(datetime.datetime(year, month, day, hour, minute, second))
            else:
               row.append(cell_value)
               
        email = row[order_of_fields["DonorEmail"]].value
        if not email:
            raise Exception("no email");
        donor = get_donor_by_email(email)
        is_new_donor = False
        if not donor:
            password = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(6))
            name = row[order_of_fields["Name"]].value
            address = row[order_of_fields["Address"]].value
            contact_number = row[order_of_fields["ContactNo"]].value
            donor = Donor(email_address=email, password_sha256=hashlib.sha256(password).hexdigest(), is_admin=False, name=name, contact_number=contact_number, address=address)
            is_new_donor = True
        date = row[order_of_fields["DonationDate"]].value
        year, month, day, hour, minute, second = xlrd.xldate_as_tuple(date, workbook.datemode)
	date = datetime.datetime(year, month, day, hour, minute, second)
        amount = row[order_of_fields["Amount"]].value
        mode = row[order_of_fields["DonationMode"]].value
        mode_description = row[order_of_fields["ModeDescription"]].value
        donation = Donation(date, amount, mode, mode_description)
        donor.donations.append(donation)
        db.session.add(donor)
        db.session.commit()  
        if is_new_donor:
            sendEmail(donor.email_address, donor_created_text.format(password), None)
        donation_ids.append(donation.id)     
    return donation_ids
开发者ID:eBay-Opportunity-Hack-Chennai-2014,项目名称:Team_Everest,代码行数:60,代码来源:__init__.py


示例10: parse_file

def parse_file(datafile):
    workbook = xlrd.open_workbook(datafile)
    sheet = workbook.sheet_by_index(0)
    header_dict = {}

    ### example on how you can get the data
    sheet_data = [[sheet.cell_value(r, col) for col in range(sheet.ncols)] for r in range(sheet.nrows)]

    cv = sheet.col_values(1, start_rowx=1, end_rowx=None)

    maxval = max(cv)
    minval = min(cv)

    maxpos = cv.index(maxval) + 1
    minpos = cv.index(minval) + 1

    maxtime = sheet.cell_value(maxpos, 0)
    realtime = xlrd.xldate_as_tuple(maxtime, 0)
    mintime = sheet.cell_value(minpos, 0)
    realmintime = xlrd.xldate_as_tuple(mintime, 0)

    data = {}

    data['maxtime'] = realtime
    data['maxvalue'] = maxval
    data['mintime'] = realmintime
    data['minvalue'] = minval
    data['avgcoast'] = sum(cv) / float(len(cv))

    return data
开发者ID:nathan-castor,项目名称:data_wrangling_in_yolodb,代码行数:30,代码来源:reading_xls_file_answer.py


示例11: parse_xls_2

def parse_xls_2(infile, account_number='unknown'):
    '''
    Parses another XLS format detected on the exports. This format is used for
    prepaid VISA cards.

    Columns:

        * Accounting date
        * Operation date
        * Card number
        * Description
        * Original amount
        * Amount EUR
    '''

    account_info = AccountInfo(account_number, '')
    book = open_workbook(infile.name)
    sheet = book.sheet_by_index(0)
    transactions = []
    for row_index in range(1, sheet.nrows):
        line = [sheet.cell(row_index, col_index).value
                for col_index in range(sheet.ncols)]
        acdate, op_date, card_no, description, orig_amount, real_amount = line
        acdate = date(*xldate_as_tuple(acdate, book.datemode)[:3])
        op_date = date(*xldate_as_tuple(op_date, book.datemode)[:3])
        transactions.append(QIFTransaction(
            acdate,
            Decimal('%.2f' % real_amount),
            description,
            '',
            ''
        ))
    return TransactionList(account_info, transactions)
开发者ID:exhuma,项目名称:ccp2qif,代码行数:33,代码来源:ccp.py


示例12: get_daily_report

def get_daily_report(sheet):
    """Get Daily Report data from excel file"""
    daily_report = []
    for i in range(sheet.nrows):
        a = []
        for j in range(sheet.ncols):
            if type(sheet.cell_value(i, 12)) == float:
                if j == 10:  # checkin date
                    checkOut = xldate_as_tuple(sheet.cell(i, j).value, book.datemode)
                    a.append(checkOut)
                if j == 8:  # checkout date
                    checkIn = xldate_as_tuple(sheet.cell(i, j).value, book.datemode)
                    a.append(checkIn)
                elif j == 1:
                    room = sheet.cell_value(i, j)
                    a.append(room)
                elif j == 2:
                    name = sheet.cell_value(i, j)
                    a.append(name)
                else:
                    pass
        if a != []:
            daily_report.append(a)

    return daily_report
开发者ID:gobuk,项目名称:creditcard-xl,代码行数:25,代码来源:cash_depo_co.py


示例13: parse_date

def parse_date(val, wb):
	try:
		date_value = xldate_as_tuple(val,wb.datemode)
		t = datetime(* (xldate_as_tuple(val,wb.datemode))).strftime('%d/%m/%Y')
		return t
	except xldate.XLDateAmbiguous:
		return val
开发者ID:ipedrazas,项目名称:blibb-api,代码行数:7,代码来源:to_json.py


示例14: parse_file

def parse_file(datafile):
    workbook = xlrd.open_workbook(datafile)
    sheet = workbook.sheet_by_index(0)

    ### example on how you can get the data
    #sheet_data = [[sheet.cell_value(r, col) for col in range(sheet.ncols)] for r in range(sheet.nrows)]

    ### other useful methods:
    # print "\nROWS, COLUMNS, and CELLS:"
    # print "Number of rows in the sheet:", 
    # print sheet.nrows
    # print "Type of data in cell (row 3, col 2):", 
    # print sheet.cell_type(3, 2)
    # print "Value in cell (row 3, col 2):", 
    # print sheet.cell_value(3, 2)
    # print "Get a slice of values in column 3, from rows 1-3:"
    # print sheet.col_values(3, start_rowx=1, end_rowx=4)

    # print "\nDATES:"
    # print "Type of data in cell (row 1, col 0):", 
    # print sheet.cell_type(1, 0)
    # exceltime = sheet.cell_value(1, 0)
    # print "Time in Excel format:",
    # print exceltime
    # print "Convert time to a Python datetime tuple, from the Excel float:",
    # print xlrd.xldate_as_tuple(exceltime, 0)
    cv  =  sheet.col_values(1,start_rowx = 1, end_rowx = None)
    data = {
            'maxtime': xlrd.xldate_as_tuple(sheet.cell_value(cv.index(max(cv))+1, 0),0),
            'maxvalue': max(cv),
            'mintime': xlrd.xldate_as_tuple(sheet.cell_value(cv.index(min(cv))+1, 0),0),
            'minvalue': min(cv),
            'avgcoast': sum(cv)/len(cv)
    }
    return data
开发者ID:hkmangla,项目名称:Data-Analyst-Nanodegree,代码行数:35,代码来源:quiz0.3.py


示例15: parse_file

def parse_file(datafile):
    workbook = xlrd.open_workbook(datafile)
    sheet = workbook.sheet_by_index(0)

    max_coast = None
    max_time = None
    min_coast = None
    min_time = None
    total_coast = 0

    for r in range(1, sheet.nrows):
        coast = sheet.cell_value(r, 1)

        if coast > max_coast or max_coast is None:
            max_coast = coast
            max_time = sheet.cell_value(r, 0)

        if coast < min_coast or min_coast is None:
            min_coast = coast
            min_time = sheet.cell_value(r, 0)

        total_coast += coast

    data = {
            'maxtime': xlrd.xldate_as_tuple(max_time, 0),
            'maxvalue': max_coast,
            'mintime': xlrd.xldate_as_tuple(min_time, 0),
            'minvalue': min_coast,
            'avgcoast': total_coast / (sheet.nrows - 1)
    }
    return data
开发者ID:j-bennet,项目名称:udacity-nano-da,代码行数:31,代码来源:parse_excel_file_return_values.py


示例16: parse_file

def parse_file(datafile):
    workbook = xlrd.open_workbook(datafile)
    sheet = workbook.sheet_by_index(0)

    data = [[sheet.cell_value(r, col)
                for col in range(sheet.ncols)]
                    for r in range(sheet.nrows)]

    coast_row = sheet.col_values(1, start_rowx=1, end_rowx=sheet.nrows)
    sum = 0
    min = sys.float_info.max
    minidx = -1
    max = -sys.float_info.max
    maxidx = -1
    count = 0
    for num in coast_row:
        if isinstance(num, float):
            sum += num
            count += 1
            if min > num:
                min = num
                minidx = coast_row.index(num)
            if max < num:
                max = num
                maxidx = coast_row.index(num)
    
    data = {
            'maxtime': xlrd.xldate_as_tuple(sheet.cell_value(maxidx + 1, 0), 0),
            'maxvalue': max,
            'mintime': xlrd.xldate_as_tuple(sheet.cell_value(minidx + 1, 0), 0),
            'minvalue': min,
            'avgcoast': sum / count
    }
    return data
开发者ID:thezaorish,项目名称:mooc,代码行数:34,代码来源:read_excel.py


示例17: process_plan_rates

def process_plan_rates(plans, filename):
	from xlrd import open_workbook, xldate_as_tuple

	wb = open_workbook(filename)
	for ws in wb.sheets():
		if not ws.name.startswith("Rate Table"): continue
		if ws.cell(0,0).value not in ("Rates Table Template v2.2", "Rates Table Template v2.3"): raise Exception("Invalid rates table: " + ws.cell(0,0).value + " in " + filename)

		rate_effective_date = datetime(*xldate_as_tuple(ws.cell(7, 1).value, wb.datemode)).isoformat()
		rate_expiration_date = datetime(*xldate_as_tuple(ws.cell(8, 1).value, wb.datemode)).isoformat()

		for r in xrange(13, ws.nrows):
			plan = ws.cell(r, 0).value
			age = ws.cell(r, 3).value
			if isinstance(age, float): age = str(int(age))

			plan_rates = plans[plan].setdefault("rates", [])
			plan_rates.append({
				"rating_area": ws.cell(r, 1).value,
				"tobacco_use": ws.cell(r, 2).value,
				"age": age,
				"rate": ws.cell(r, 4).value,
				"effective": rate_effective_date, # applies to all rates, so this isn't the right place to encode it
				"expires": rate_expiration_date, # applies to all rates, so this isn't the right place to encode it
			})
开发者ID:JoshData,项目名称:dchbx,代码行数:25,代码来源:parse_plan_template_files.py


示例18: parse_file

def parse_file(datafile):
    workbook = xlrd.open_workbook(datafile)
    sheet = workbook.sheet_by_index(0)


    data = [[sheet.cell_value(r, col) for col in range(sheet.ncols)] for r in range(sheet.nrows)]

    cv =sheet.col_values(1, start_rowx=1, end_rowx=None)
    maxval = max(cv)
    minval = min(cv)

    maxpos=cv.index(maxval) +1
    minpos=cv.index(minval) +1

    maxtime = sheet.cell_value(maxpos,0)
    realtime = xlrd.xldate_as_tuple(maxtime,0)

    mintime = sheet.cell_value(minpos,0)
    realmintime = xlrd.xldate_as_tuple(mintime,0)

    

    data = {
            'maxtime': realtime,
            'maxvalue': maxval,
            'mintime': realmintime,
            'minvalue': minval,
            'avgcoast': sum(cv) / float(len(cv))
    }
    return data
开发者ID:chunghoony,项目名称:UdacityDataAnalystNanoDegree,代码行数:30,代码来源:L1_Ex4.py


示例19: parse_excel

def parse_excel(input_directory, output_directory):
    for path, dirs, files in os.walk(input_directory):
        for file_name in files:
            if not file_name.endswith('.xlsx'):
                continue

            wb = xlrd.open_workbook(os.path.join(path, file_name))
            sh = wb.sheet_by_index(0)

            records = []
            for rownum in range(1, sh.nrows):
                row = sh.row_values(rownum)
                year, month, day = xlrd.xldate_as_tuple(row[2],
                                                        wb.datemode)[:3]
                hour, minute, second = xlrd.xldate_as_tuple(row[3],
                                                            wb.datemode)[3:]
                records.append({
                    'row': int(row[0]),
                    'device': row[1],
                    'year': year,
                    'month': month,
                    'day': day,
                    'hour': hour,
                    'minute': minute,
                    'second': second,
                    'latitude': row[4],
                    'longitude': row[5],
                    'speed': row[6],
                    'direction': row[7],
                    'numSatellites': int(row[8])
                })
            json_file_name = os.path.splitext(file_name)[0] + '.json'
            json_path = os.path.join(output_directory, json_file_name)
            with open(json_path, 'w') as f:
                json.dump(records, f, separators=(',', ':'))
开发者ID:indodutch,项目名称:kumbhserial,代码行数:35,代码来源:parse_excel.py


示例20: parse_file

def parse_file(datafile):
    workbook = xlrd.open_workbook(datafile)
    sheet = workbook.sheet_by_index(0)
    

    
    ### example on how you can get the data
    minval = min(sheet.col_values(1,1,sheet.nrows))
    maxval = max(sheet.col_values(1,1,sheet.nrows))
    avg = (sum(sheet.col_values(1,1,sheet.nrows))/(sheet.nrows-1))
    
    #print minval
    minpos = sheet.col_values(1,1, sheet.nrows-1).index(minval) + 1
    #print minpos
    #print maxval
    maxpos = sheet.col_values(1,1, sheet.nrows-1).index(maxval) + 1
    #print maxpos
    
    maxtime = xlrd.xldate_as_tuple(sheet.cell_value(maxpos,0),0)
    mintime = xlrd.xldate_as_tuple(sheet.cell_value(minpos,0),0)
    print(maxtime)
    #print mintime
    
        
    '''sheet_data = [sheet.cell_value(r, c) for r in range(1, sheet.nrows)
                                          for c in range(0, 1)]
    minval = min(sheet_data)
    maxval = max(sheet_data)
    print(sheet_data.col_values(1,1,100))'''
    #print(maxval)
    
    ### other useful methods:
    # print "\nROWS, COLUMNS, and CELLS:"
    # print "Number of rows in the sheet:", 
    # print sheet.nrows
    # print "Type of data in cell (row 3, col 2):", 
    # print sheet.cell_type(3, 2)
    # print "Value in cell (row 3, col 2):", 
    # print sheet.cell_value(3, 2)
    # print "Get a slice of values in column 3, from rows 1-3:"
    # print sheet.col_values(3, start_rowx=1, end_rowx=4)

    # print "\nDATES:"
    # print "Type of data in cell (row 1, col 0):", 
    # print sheet.cell_type(1, 0)
    # exceltime = sheet.cell_value(1, 0)
    # print "Time in Excel format:",
    # print exceltime
    # print "Convert time to a Python datetime tuple, from the Excel float:",
    # print xlrd.xldate_as_tuple(exceltime, 0)
    
    
    data = {
            'maxtime': maxtime,
            'maxvalue': maxval,
            'mintime': mintime,
            'minvalue': minval,
            'avgcoast': avg
    }
    return data
开发者ID:nehaavishwa,项目名称:DataWrangle,代码行数:60,代码来源:Excel_process.py



注:本文中的xlrd.xldate_as_tuple函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python timemachine.xrange函数代码示例发布时间:2022-05-26
下一篇:
Python xlrd.open_workbook函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap