当前位置:网站首页>Datetime data type - min() get the earliest date and date_ Range() creates a date range, timestamp() creates a timestamp, and tz() changes the time zone
Datetime data type - min() get the earliest date and date_ Range() creates a date range, timestamp() creates a timestamp, and tz() changes the time zone
2022-06-26 04:50:00 【I am a little monster】
Catalog
tz Parameter to specify the time zone
tz_localize: Used to encode the time zone
min(): Get the earliest date
>>> import pandas as pd
>>> ebola=pd.read_csv(r'D:\pandas Flexible use \pandas_for_everyone-master\data/country_timeseries.csv',parse_dates=[0])
>>> print(ebola['Date'].min())
2014-03-22 00:00:date_range: Create date range
>>> r=pd.date_range(start='1999-12-01',end='1999-12-31')
>>> print(r)
DatetimeIndex(['1999-12-01', '1999-12-02', '1999-12-03', '1999-12-04',
'1999-12-05', '1999-12-06', '1999-12-07', '1999-12-08',
'1999-12-09', '1999-12-10', '1999-12-11', '1999-12-12',
'1999-12-13', '1999-12-14', '1999-12-15', '1999-12-16',
'1999-12-17', '1999-12-18', '1999-12-19', '1999-12-20',
'1999-12-21', '1999-12-22', '1999-12-23', '1999-12-24',
'1999-12-25', '1999-12-26', '1999-12-27', '1999-12-28',
'1999-12-29', '1999-12-30', '1999-12-31'],
dtype='datetime64[ns]', freq='D')Offset parameter
date_range There is a parameter in the freq, Used to select from the range you specify , You can choose working days (B)、 At the beginning of (MS)、 Month end working day (BM)、 The working day at the beginning of the quarter (BQS) etc. .
Some examples are given below ,freq All possible reference values can be referred to date_range Create date range freq Parameter value table _ I am a little monster blog -CSDN Blog
>>> r=pd.date_range(start='1999-12-01',end='1999-12-31',freq='B')
>>> print(r)
DatetimeIndex(['1999-12-01', '1999-12-02', '1999-12-03', '1999-12-06',
'1999-12-07', '1999-12-08', '1999-12-09', '1999-12-10',
'1999-12-13', '1999-12-14', '1999-12-15', '1999-12-16',
'1999-12-17', '1999-12-20', '1999-12-21', '1999-12-22',
'1999-12-23', '1999-12-24', '1999-12-27', '1999-12-28',
'1999-12-29', '1999-12-30', '1999-12-31'],
dtype='datetime64[ns]', freq='B')
>>> r=pd.date_range(start='1999-12-01',end='1999-12-31',freq='BM')
>>> print(r)
DatetimeIndex(['1999-12-31'], dtype='datetime64[ns]', freq='BM'
>>> r=pd.date_range(start='1999-1-01',end='1999-12-31',freq='BQS')
>>> print(r)
DatetimeIndex(['1999-01-01', '1999-04-01', '1999-07-01', '1999-10-01'], dtype='datetime64[ns]', freq='BQS-JAN')Timestamp: Create timestamps
>>> depart=pd.Timestamp('2022-08-29 07:00',tz='US/Eastern')#tz Used to specify the time zone , It will be briefly introduced under the timestamp
>>> print(depart)
2022-08-29 07:00:00-04:00
>>> print(type(depart))
<class 'pandas._libs.tslibs.timestamps.Timestamp'>tz: The time zone
python Of pytz The library is designed to handle time zones
tz Parameter to specify the time zone
>>> depart=pd.Timestamp('2022-08-29 07:00',tz='US/Eastern')
>>> print(depart)
2022-08-29 07:00:00-04:00tz_localize: Used to encode the time zone
>>> arrive=pd.Timestamp('2022-08-29 07:00')
>>> print(arrive)
2022-08-29 07:00:00
>>> arrive=arrive.tz_localize('US/Eastern')# Specify the time zone of the created arrival time as the eastern United States
>>> print(arrive)
2022-08-29 07:00:00-04:00
to_convert: Change time zone
The transformation time zone here must be assigned to the original variable of the date , To change the time zone of the date variable
>>> depart=pd.Timestamp('2022-08-29 07:00',tz='US/Eastern')
>>> arrive=pd.Timestamp('2022-08-29 12:00')
>>> arrive=arrive.tz_localize('US/Pacific')
>>> print(arrive.tz_convert('US/Eastern'))
2022-08-29 15:00:00-04:00
# Only time in the same time zone can be calculated , The above time zone conversion is not assigned to arrive, So there is no real arrive Your time zone has changed , Here, you need to convert before you can perform the operation
>>> print(arrive.tz_convert('US/Eastern')-depart)
0 days 08:00:00边栏推荐
- How to carry out word-of-mouth marketing for enterprises' products and services? Can word of mouth marketing be done on behalf of others?
- Tips for using idea
- Jenkins introduces custom jars
- LeetCode 94. Middle order traversal of binary tree
- Rdkit chemical formula molecular formula search
- 22.2.8
- 文件上传与安全狗
- 202.2.9
- Nightmare
- 2022.2.15
猜你喜欢

1.18 learning summary

ROS 笔记(07)— 客户端 Client 和服务端 Server 的实现

torchvision_transform(图像增强)

Statsmodels Library -- linear regression model

记录一次循环引用的问题

Créateur de génie: cavalier solitaire, magnat de la technologie et ai | dix ans d'apprentissage profond

File upload and security dog

UWB超高精度定位系统架构图

NVM installation and use and NPM package installation failure record

How to use the configured slave data source for the scheduled task configuration class scheduleconfig
随机推荐
[H5 development] 01 take you to experience H5 development from a simple page ~ the whole page implementation process from static page to interface adjustment manual teaching
2022.2.16
Multipass Chinese document - remote use of multipass
numpy 随机数
2.8 learning summary
[H5 development] 03- take you hand in hand to improve H5 development - single submission vs batch submission with a common interface
Use shell script to analyze system CPU, memory and network throughput
Compiling and installing phpredis extension on MAC
Some parameter settings and feature graph visualization of yolov5-6.0
Numpy general function
Créateur de génie: cavalier solitaire, magnat de la technologie et ai | dix ans d'apprentissage profond
Yolov5 super parameter setting and data enhancement analysis
Text horizontal alignment attribute text align and element vertical alignment attribute vertical align
Numpy random number
记录一次循环引用的问题
Yapi cross domain request plug-in installation
JWT token authentication verification
PHP installation SSH2 extension
1.24 learning summary
Is education important or ability important in software testing