pandas的object对象转时间对象

    xiaoxiao2021-03-25  113

    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的时间类型,提取年份

    转载请注明原文地址: https://ju.6miu.com/read-14422.html

    最新回复(0)