日期格式来自" 01/03 / 2000" to" datetime.datetime(2000,3,1,0,0)"

时间:2018-06-15 10:06:54

标签: python-3.x pandas

嗨大家我如何转换CSV文件日期格式来自" 01/03/2000" to" datetime.datetime(2000,3,1,0,0)"日期列必须转换为此" datetime.datetime(2000,3,1,0,0)"格式

    apl = pd.read_csv('Data_Resource/aapl.csv')
    print(apl.head())
    Unnamed: 0  adj_close   close        date    high     low    open   volume
0           0      31.68  130.31  2000-03-01  132.06  118.50  118.56  38478000
1           1      29.66  122.00  2000-03-02  127.94  120.69  127.00  11136800
2           2      31.12  128.00  2000-03-03  128.23  120.00  124.87  11565200
3           3      30.56  125.69  2000-03-06  129.13  125.00  126.00  7520000 

日期

    [datetime.datetime(2000, 3, 1, 0, 0),
    datetime.datetime(2000, 3, 2, 0, 0),
    datetime.datetime(2000, 3, 3, 0, 0),
    datetime.datetime(2000, 3, 6, 0, 0),

1 个答案:

答案 0 :(得分:0)

你可以尝试

pd.to_datetime(df['date'])