pandas的object对象转时间对象

来源:互联网 发布:收徒网站源码 编辑:程序博客网 时间:2024/06/18 14:23
df = pd.read_table('G:/tc/dataset/user_view.txt', sep=",")#读取文件
df.columns = ["a", "b", "c"]#列命名
df['c'] = pd.to_datetime(df['c'],format='%Y-%m-%d %H:%M:%S')#将读取的日期转为datatime格式
x=[i.year for i in df["c"]]#遍历时间变量,提取年份,使用datatime模块的属性和方法

print x


pandas中将object对象转为datatime的时间类型,提取年份

0 0