[英]Pandas - conversion to datetime
I have this small issue, where I first concatenate 3 columns in a DataFrame ['Year', 'Month', 'Day'] into a single column called ['Date'], and then I apply to this column datetime conversion, but afterwards when I check this column with .info() method, it still contains objects, not datetime objects: 我有一个小问题,我首先将DataFrame ['Year','Month','Day']中的3列连接到称为['Date']的单个列中,然后将其应用于此列的datetime转换,但是之后,当我使用.info()方法检查此列时,它仍然包含对象,而不是datetime对象:
DataFrame I am operating on is the first item in 'output' list, hence the address I apply before .info() method. 我正在操作的DataFrame是“输出”列表中的第一项,因此我在.info()方法之前应用的地址。
Any ideas why it does not obey me? 有什么想法为什么不服从我吗?
You need to assign it back to dataframe['Date']. 您需要将其分配回dataframe ['Date']。 pd.to_datetime
is not an inplace operation it returns back the Series with dtype datetime64. pd.to_datetime
不是就地操作,它以dtype datetime64返回Series。
dataframe['Date'] = pd.to_datetime(dataframe['Date'], format='%Y-%m-%d')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.