python将dataframe中的CST时间格式转化为标准的时间(年月日)

用pandas读入文件,时间格式是CST  想转为标准的年月日格式

代码:

def cst_to_str(cstTime):

    tempTime = time.strptime(cstTime,'%a %b %d %H:%M:%S CST %Y')

    resTime = time.strftime('%Y-%m-%d',tempTime)

    return resTime


df_info['adddate'] = df_info['adddate'].apply(cst_to_str )

原来的格式如下:

                     

经过转换处理后:

                  

猜你喜欢

转载自www.cnblogs.com/chenmeng7/p/9395847.html