python - How to convert Python DataFrame column with Excel 5 digit date to yyyy-mm-dd
问题描述
I'm trying to convert an entire column containing a 5 digit date code (EX: 43390, 43599) to a normal date format. This is just to make data analysis easier, it doesn't matter which way it's formatted. In a series, the DATE column looks like this:
1 43390
2 43599
3 43605
4 43329
5 43330
...
264832 43533
264833 43325
264834 43410
264835 43461
264836 43365
I don't understand previous submissions with this question, and when I tried code such as
date_col = df.iloc[:,0]
print((datetime.utcfromtimestamp(0) + timedelta(date_col)).strftime("%Y-%m-%d"))
I get this error
unsupported type for timedelta days component: Series
Thanks, sorry if this is a basic question.
解决方案
您正在调用数据框并将其分配给date_col
. 例如,如果要获取第一行的值,请使用date_col = df.iloc[0]
. 这将返回值。Timedelta 采用整数值,而不是 Series。
推荐阅读
- mysql - GCP 上的 MYSQL DB 小升级
- javascript - 如果 2 个单选按钮具有相同的值,则打开第一个选中的页面
- postgresql - 输出表中不存在的值
- node.js - 计算要从 mongodb 中嵌套引用数组的查找查询中获取的元素数
- google-sheets-api - 更新谷歌电子表格中的值后的Wix PUT函数
- javascript - 我可以将 Windows.print 从 chrome 设置为 IE 模式吗?
- security - 如何验证请求标头是否由特定 Web 应用程序添加
- powershell - SPI_GETCURSORSHADOW 0x101A - 无法获取布尔值
- python - 查找给定子字符串 Python 的最长连续运行
- python - 检查字符串是否具有 .pdf 扩展名