[英]Pandas- Unnecessay values included while converting a column into datetime format
I made a column by concatenating integers and converting into string format. 我通过连接整数并将其转换为字符串格式来创建一列。 Later I am converting the string column into datetime, everything is working just fine except an additional day field is added to the new datetime column.
稍后,我将字符串列转换为日期时间,除了在新的日期时间列中添加了一个额外的日字段之外,其他一切工作都很好。 Here is what I mean to say.
这就是我的意思。
I am making a column of type string like this,
'1-1992' where 1 reflects month and 1992 reflects year
But, when I am converting the column with "Month-Year" to datetime format,an additional "Day" field is getting added to the new column, here is what it looks like. 但是,当我将“年份”列转换为日期时间格式时,新的“日”字段将添加到新列中,如下所示。
"1992-01-01" (last 01 is added to all the values,which i don't want,
I only want month and year keeping datetime format -
with me).
How can I get rid of the last 01 which is present in all the rows, keeping the format to datetime ? 如何摆脱所有行中出现的最后一个01,将格式保持为datetime? Thank you.
谢谢。
import datetime
df[date_column] = df[date_column].apply(lambda x : datetime.datetime.strftime(x, "%Y-%m"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.