如何在 pandas 数据框中将时间戳转换为datetime.date? [英] How do I convert timestamp to datetime.date in pandas dataframe?

查看:116
本文介绍了如何在 pandas 数据框中将时间戳转换为datetime.date?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在日期上将2个pandas数据框合并在一起,但是它们当前具有不同的日期类型. 1是时间戳(从excel导入),另一个是datetime.date.

I need to merge 2 pandas dataframes together on dates, but they currently have different date types. 1 is timestamp (imported from excel) and the other is datetime.date.

有什么建议吗?

我已经尝试过pd.to_datetime().date,但这仅适用于单个项目(例如df.ix[0,0]),它不能让我应用于整个系列(例如df['mydates'])或数据框.

I've tried pd.to_datetime().date but this only works on a single item(e.g. df.ix[0,0]), it won't let me apply to the entire series (e.g. df['mydates']) or the dataframe.

推荐答案

我从同事那里得到了一些帮助.

I got some help from a colleague.

这似乎解决了上面发布的问题

This appears to solve the problem posted above

pd.to_datetime(df['mydates']).apply(lambda x: x.date())

这篇关于如何在 pandas 数据框中将时间戳转换为datetime.date?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆