【pandas】pandas.to_datatime()---时间格式转换

标准时间格式:2012-12-21

时间转换函数:pandas.to_datatime()

# -*- coding: utf-8 -*-

# 生成数据
import pandas as pd 
data = {'birth':['2011/12/01','2012/12/02','2012/12/03','2012/12/04','2012/12/05']}
frame = pd.DataFrame(data)
print(frame)
"""
        birth
0  2011/12/01
1  2012/12/02
2  2012/12/03
3  2012/12/04
4  2012/12/05
"""

# 标准时间格式
frame['birth'] = pd.to_datetime(data['birth'])
print(frame)
"""
       birth
0 2011-12-01
1 2012-12-02
2 2012-12-03
3 2012-12-04
4 2012-12-05
"""

猜你喜欢

转载自www.cnblogs.com/wanglei5205/p/8971020.html