Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Python localtime,TypeError:无法将序列转换为

Python localtime,TypeError:无法将序列转换为
EN

Stack Overflow用户
提问于 2020-04-25 14:47:11
回答 1查看 297关注 0票数 0

我有一个DataFrame:enter image description here

我想在本地时间显示"TimeStamps“,但不要运行。

代码语言:javascript
运行
AI代码解释
复制
time.localtime(data_user['TimeStamps'].astype(int))

错误:

代码语言:javascript
运行
AI代码解释
复制
TypeError: cannot convert the series to <class 'int'>

我怎样才能做到这一点呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-25 14:57:22

使用箭头包

代码语言:javascript
运行
AI代码解释
复制
from datetime import datetime
import arrow

now = datetime.utcnow()

print(arrow.get(now).to('local').format())
# 2020-04-25 15:55:31+01:00

如下所示:

代码语言:javascript
运行
AI代码解释
复制
def to_local(x):
    return arrow.get(x).to('local').format() 

data_user['TimeStamps']= data_user['TimeStamps'].apply(to_local)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61427475

复制
相关文章

相似问题

Python TypeError:无法将字典更新序列元素#1转换为序列

1143

plotly: TypeError:无法将字典更新序列元素#0转换为序列

20

Python- TypeError:无法将序列转换为

228

如何修复“TypeError:无法将字典更新序列元素#0转换为序列”

129

元组到Dict ::TypeError:无法将字典更新序列元素#0转换为序列

310
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档