【问题标题】:Date type convert error in Python (XLSB to CSV): year 2022 --> 2092Python 中的日期类型转换错误(XLSB 到 CSV):2022 年 --> 2092 年
【发布时间】:2022-11-20 05:42:39
【问题描述】:

我有一个 XLSB 文件可以在 Python 中转换为 CSV,但 CSV 文件中的年份从 2022 年更改为 2092 年。希望得到您的帮助和指导。 谢谢你。

test = pd.read_excel('./date_error.xlsb', engine='pyxlsb', sheet_name='date', skiprows=0)
test = pd.read_csv('./date_error.csv')
test = test.astype({'Date1': 'datetime64[D]',\
                'Date2': 'datetime64[D]'}) 
test.to_csv('./test.csv', index=False)

该文件附于此。 https://github.com/LiamV9/LiamV9/raw/main/date_error.xlsb

【问题讨论】:

    标签: date xlsb


    【解决方案1】:

    四处搜索,我找到了一个有效的方法:

    df[['Date']] = df[['Date']].apply(pd.to_numeric, errors='coerce', axis = 1)
    df['Date'] = pd.to_datetime(df['Date'], unit='d', origin='1899-12-30')
    

    另一个问题是我有一些列以十进制格式“0.5998”签入/签出时间。

    使用 Excel 格式转换器将时间转换为时间:上午 10:30。

    我们如何在 Python 中将其自动化?

    【讨论】:

      猜你喜欢
      • 2019-04-13
      • 1970-01-01
      • 2019-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-07
      • 1970-01-01
      相关资源
      最近更新 更多