[英]Date type convert error in Python (XLSB to CSV): year 2022 --> 2092
我有一个 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
四处搜索,我找到了一个有效的方法:
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 中实现自动化?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.