当前位置:网站首页>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边栏推荐
猜你喜欢

A method of quickly transplanting library function code to register code by single chip microcomputer

08_ Spingboot integrated redis

天才制造者:独行侠、科技巨头和AI|深度学习崛起十年

Physical design of database design (2)

Introduction to markdown grammar

Rdkit chemical formula molecular formula search

Database design (3): database maintenance and optimization

Illustration of ONEFLOW's learning rate adjustment strategy

Yapi cross domain request plug-in installation

1.17 learning summary
随机推荐
Svn error command revert error previous operation has not finished; run ‘ cleanup‘ if
Rsync common error messages (common errors on the window)
What is the best way to store chat messages in a database? [Close] - best way to store chat messages in a database? [closed]
Thinkphp6 parsing QR code
numpy 索引及切片
A method of quickly transplanting library function code to register code by single chip microcomputer
torchvision_ Transform (image enhancement)
记录一次循环引用的问题
广和通联合安提国际为基于英伟达 Jetson Xavier NX的AI边缘计算平台带来5G R16强大性能
2022.2.11
Simple use of redis in laravel
2022.1.23
Condition query
图解OneFlow的学习率调整策略
Interpretation of yolov5 training results
微信小程序保存圖片的方法
Floyd
文件上传与安全狗
1.12 learning summary
2022.2.15