Conversion between datetime, Timestamp and datetime64

Introduction kit

import datetime
import numpy as np
import pandas as pd

 

Overview 

from IPython.display import Image
from IPython.core.display import HTML 
Image(url= "https://i.stack.imgur.com/uiXQd.png")

 

A library .datetime

datetime library has four main target

Time - Time is limited, in hours, minutes, seconds and microseconds
date - Only in the month and day,
datetime - date and time of all components
timedelta - the amount of time the maximum number of days

(1) datetime create

 

(2)datetime转Timestamp

(3)datetime转np.datetime64

 

Two .pandas library

(1) Create a Timestamp

(2)Timestamp转datetime

Gets the date and time from the timestamp

(3)Timestamp转np.datetime64[s]

 

 

Three .numpy library

NumPy no separate date and time of the object, only a single object to represent datetime64 time. datetime datetime objects with microsecond precision module (millionths of a second). NumPy of datetime64 object allows you to accuracy from the number of hours has been set to attosecond (10 ^ -18). Its constructor a more flexible, various inputs.

(1) create numPy of datetime64 objects and timedelta64

(2)np.datetime64[s]转datetime64[ns]

 

(3)np.datetime64[s]转datetime.datetime

 

(4)np.datetime64[s]转Timestamp

 

 

参考文献:

【1】字符串转各种日期格式

【2】pandas时间戳索引:Datetimeindex

【3】Pandas日期数据处理:如何按日期筛选、显示及统计数据

【4】python - 在datetime,Timestamp和datetime64之间转换

 

Guess you like

Origin www.cnblogs.com/nxf-rabbit75/p/11111825.html