第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在Python中以Excel格式讀取日期?

如何在Python中以Excel格式讀取日期?

翻閱古今 2019-10-28 14:59:35
如何在Python中將Excel日期(以數(shù)字格式)轉換為正確的日期?
查看完整描述

3 回答

?
叮當貓咪

TA貢獻1776條經驗 獲得超12個贊

您可以使用xlrd。


從其文檔中,您可以了解到,日期始終存儲為數(shù)字。但是,您可以xldate_as_tuple將其轉換為python日期。


注意:PyPI上的版本似乎比xlrd網站上的版本更新。


查看完整回答
反對 回復 2019-10-28
?
當年話下

TA貢獻1890條經驗 獲得超9個贊

這是無風險的裸指安全帶版本:


import datetime


def minimalist_xldate_as_datetime(xldate, datemode):

    # datemode: 0 for 1900-based, 1 for 1904-based

    return (

        datetime.datetime(1899, 12, 30)

        + datetime.timedelta(days=xldate + 1462 * datemode)

        )


查看完整回答
反對 回復 2019-10-28
?
翻過高山走不出你

TA貢獻1875條經驗 獲得超3個贊

經過測試并等待幾天的反饋后,我將在xlrd的xldate模塊中svn-commit-commit以下新功能……請注意,仍在運行Python 2.1或2.2的頑固派將無法使用該功能。


##

# Convert an Excel number (presumed to represent a date, a datetime or a time) into

# a Python datetime.datetime

# @param xldate The Excel number

# @param datemode 0: 1900-based, 1: 1904-based.

# <br>WARNING: when using this function to

# interpret the contents of a workbook, you should pass in the Book.datemode

# attribute of that workbook. Whether

# the workbook has ever been anywhere near a Macintosh is irrelevant.

# @return a datetime.datetime object, to the nearest_second.

# <br>Special case: if 0.0 <= xldate < 1.0, it is assumed to represent a time;

# a datetime.time object will be returned.

# <br>Note: 1904-01-01 is not regarded as a valid date in the datemode 1 system; its "serial number"

# is zero.

# @throws XLDateNegative xldate < 0.00

# @throws XLDateAmbiguous The 1900 leap-year problem (datemode == 0 and 1.0 <= xldate < 61.0)

# @throws XLDateTooLarge Gregorian year 10000 or later

# @throws XLDateBadDatemode datemode arg is neither 0 nor 1

# @throws XLDateError Covers the 4 specific errors


def xldate_as_datetime(xldate, datemode):

    if datemode not in (0, 1):

        raise XLDateBadDatemode(datemode)

    if xldate == 0.00:

        return datetime.time(0, 0, 0)

    if xldate < 0.00:

        raise XLDateNegative(xldate)

    xldays = int(xldate)

    frac = xldate - xldays

    seconds = int(round(frac * 86400.0))

    assert 0 <= seconds <= 86400

    if seconds == 86400:

        seconds = 0

        xldays += 1

    if xldays >= _XLDAYS_TOO_LARGE[datemode]:

        raise XLDateTooLarge(xldate)


    if xldays == 0:

        # second = seconds % 60; minutes = seconds // 60

        minutes, second = divmod(seconds, 60)

        # minute = minutes % 60; hour    = minutes // 60

        hour, minute = divmod(minutes, 60)

        return datetime.time(hour, minute, second)


    if xldays < 61 and datemode == 0:

        raise XLDateAmbiguous(xldate)


    return (

        datetime.datetime.fromordinal(xldays + 693594 + 1462 * datemode)

        + datetime.timedelta(seconds=seconds)

        )

分享編輯


查看完整回答
反對 回復 2019-10-28
  • 3 回答
  • 0 關注
  • 2162 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號