如何使用大熊猫分开日期,小时和时区信息?
我很好奇如何使用pandas在.csv文件中处理此类信息:
2022-08-11 11:50:01 America/los_angeles
我的目标是提取日期,小时和分钟以及时区信息以进行进一步分析。
我试图使用以下方式提出日期和时间: df ['date'] = pd.to_datetime(df ['dateTime'])。dt.date
,
但由于字符串在末尾而遇到了错误。除了使用特定索引提取日期和时间之外,还有更好,更快的方法吗?太感谢了。
I'm curious about how to use pandas to deal with this sort of info in a .csv file:
2022-08-11 11:50:01 America/Los_Angeles
My goal is to extract the date, hour and minute, and the timezone info for further analysis.
I have tried to lift out the date and time using:df['Date'] = pd.to_datetime(df['datetime']).dt.date
but got an error because of the string at the end. Other than extracting the date and time using specific indices, is there any better and quicker way? Thank you so much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Pandas无法处理具有不同时区的DateTime列。您可以首先分组
datetime
和timezone
在单独的列中:现在您可以执行以下操作:
如果要在
中表达所有本地日期/时间America/los_angeles
时间:您可以将
更改为您喜欢的时区。
pandas cannot handle a datetime column with different timezones. You can start by splitting the
datetime
andtimezone
in separate columns:Now you are able to do the following:
If you want to express all local date/times in
America/Los_Angeles
time:You can change
America/Los_Angeles
to the timezone of your liking.