【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
"""


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM