Hướng dẫn giải thích cách so sánh hai ngày trong Python. Nó có nhiều phương pháp để xác định ngày nào lớn hơn, vì vậy hướng dẫn cũng liệt kê các mã ví dụ khác nhau để xây dựng các cách tiếp cận khác nhau
Sử dụng Mô-đun >>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
98 và Toán tử >>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
99/import pandas as pd
import numpy as np
import datetime
000 để so sánh hai ngày trong Python
import pandas as pd
import numpy as np
import datetime
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'98 và các toán tử so sánh đơn giản
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'99 hoặc
import pandas as pd
import numpy as np
import datetime
000 có thể được sử dụng để so sánh hai ngày. Mô-đun >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'98 cung cấp phương thức
import time
first_date = "30/11/2020"
second_date = "12/10/2019"
formatted_date1 = time.strptime[first_date, "%d/%m/%Y"]
formatted_date2 = time.strptime[second_date, "%d/%m/%Y"]
print[formatted_date1 > formatted_date2]
0 nhận ba tham số để tạo ngày từ năm, tháng và ngày. Sau khi nhận được ngày tháng, chúng có thể được so sánh bằng cách sử dụng các toán tử so sánh mô-đun nhập khẩu
import pandas as pd
import numpy as np
import datetime
tạo khung dữ liệu giả
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
tuổi_ngày_yêu_thích_màu_lớptênWillard Morris2001-02-1996màu xanh da trời88Willard MorrisAl Jennings1908-05-1997màu đỏ92Al JenningsOmar Mullins2204-28-1996màu vàng95Omar MullinsSpencer McDaniel2112-16-1995màu xanh lá cây70Spencer McDanieltạo một cột mới với năm của trường ngày 'birth_date'
tuổibirth_datefavorite_colorgradenameyearWillard Morris2001-02-1996blue88Willard Morris1996Al Jennings1908-05-1997red92Al Jennings1997Omar Mullins2204-28-1996vàng95Omar Mullins1996Spencer McDaniel2112-16-1995green70Spencer McDaniel1995tạo một cột mới với trường tháng ngày 'birth_date'
agebirth_datefavorite_colorgradenameyearmonthWillard Morris2001-02-1996blue88Willard Morris19961Al Jennings1908-05-1997red92Al Jennings19978Omar Mullins2204-28-1996yellow95Omar Mullins19964Spencer McDaniel2112-16-1995green70Spencer McDaniel199512agebirth_datefavorite_colorgradenameyearmonthmonth_yearWillard Morris2001-02-1996blue88Willard Morris199611996-01Al Jennings1908-05-1997red92Al Jennings199781997-08Omar Mullins2204-28-1996yellow95Omar Mullins199641996-04Spencer McDaniel2112Mặc dù số học ngày và giờ được hỗ trợ, trọng tâm của việc triển khai là trích xuất thuộc tính hiệu quả để định dạng và thao tác đầu ra
Xem thêm
Mô-đun>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False9
Các chức năng liên quan đến lịch chung
Mô-đun>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0
Thời gian truy cập và chuyển đổi
Mô-đun>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1
Múi giờ cụ thể đại diện cho cơ sở dữ liệu múi giờ IANA
ngày đóng góiThư viện của bên thứ ba với múi giờ mở rộng và hỗ trợ phân tích cú pháp
Đối tượng nhận thức và ngây thơ¶
Các đối tượng ngày và giờ có thể được phân loại là "nhận biết" hoặc "ngây thơ" tùy thuộc vào việc chúng có bao gồm thông tin múi giờ hay không
Với kiến thức đầy đủ về các điều chỉnh thời gian chính trị và thuật toán hiện hành, chẳng hạn như múi giờ và thông tin về thời gian tiết kiệm ánh sáng ban ngày, một đối tượng nhận biết có thể định vị chính nó so với các đối tượng nhận biết khác. Một đối tượng nhận thức đại diện cho một thời điểm cụ thể không thể giải thích được. 1
Một đối tượng ngây thơ không chứa đủ thông tin để định vị chính nó một cách rõ ràng so với các đối tượng ngày/giờ khác. Việc một đối tượng ngây thơ đại diện cho Giờ phối hợp quốc tế [UTC], giờ địa phương hay thời gian ở một số múi giờ khác hoàn toàn phụ thuộc vào chương trình, giống như việc một số cụ thể đại diện cho mét, dặm hay khối lượng hay không là tùy thuộc vào chương trình. Các đối tượng ngây thơ dễ hiểu và dễ làm việc với cái giá phải trả là bỏ qua một số khía cạnh của thực tế
Đối với các ứng dụng yêu cầu các đối tượng nhận biết, các đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 có thuộc tính thông tin múi giờ tùy chọn,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4, có thể được đặt thành một thể hiện của một lớp con của lớp trừu tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4. Các đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 này nắm bắt thông tin về độ lệch so với thời gian UTC, tên múi giờ và liệu thời gian tiết kiệm ánh sáng ban ngày có hiệu lực hay không
Chỉ có một lớp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 cụ thể, lớp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8, được cung cấp bởi mô-đun
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7. Lớp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8 có thể biểu thị các múi giờ đơn giản với độ lệch cố định từ UTC, chẳng hạn như chính UTC hoặc các múi giờ EST và EDT của Bắc Mỹ. Hỗ trợ các múi giờ ở mức độ chi tiết sâu hơn tùy thuộc vào ứng dụng. Các quy tắc điều chỉnh thời gian trên toàn thế giới mang tính chính trị hơn là hợp lý, thay đổi thường xuyên và không có tiêu chuẩn nào phù hợp cho mọi ứng dụng ngoài UTC
Hằng số¶
Mô-đun
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 xuất các hằng số saungày giờ. THÁNG NĂM ¶
Số năm nhỏ nhất được phép trong một đối tượng
import pandas as pd
import numpy as np
import datetime
62 hoặc >>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7.
import pandas as pd
import numpy as np
import datetime
64 là import pandas as pd
import numpy as np
import datetime
65ngày giờ. MAX NĂM ¶Số năm lớn nhất được phép trong một đối tượng
import pandas as pd
import numpy as np
import datetime
62 hoặc >>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7.
import pandas as pd
import numpy as np
import datetime
68 là import pandas as pd
import numpy as np
import datetime
69ngày giờ. UTC ¶Bí danh cho múi giờ UTC đơn lẻ
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
40Mới trong phiên bản 3. 11
Các loại có sẵn¶
lớp ngày giờ. ngàyMột ngày ngây thơ được lý tưởng hóa, giả sử rằng lịch Gregorian hiện tại luôn có hiệu lực. Thuộc tính.
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
41, raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
42 và raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
43lớp ngày giờ. thời gianThời gian lý tưởng hóa, không phụ thuộc vào bất kỳ ngày cụ thể nào, giả sử rằng mỗi ngày có chính xác 24*60*60 giây. [Không có khái niệm “giây nhuận” ở đây. ] Thuộc tính.
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
44, raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
45, raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
46, raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
47 và >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4lớp ngày giờ. ngày giờ
Một sự kết hợp của một ngày và một thời gian. Thuộc tính.
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
41, raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
42, raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
43, raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
44, raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
45, raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
46, raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
47 và >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4lớp ngày giờ. đồng hồ thời gian
Khoảng thời gian thể hiện sự khác biệt giữa hai phiên bản
import pandas as pd
import numpy as np
import datetime
62, >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 hoặc
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 đối với độ phân giải micro giâylớp ngày giờ. tzinfo
Một lớp cơ sở trừu tượng cho các đối tượng thông tin múi giờ. Chúng được sử dụng bởi các lớp
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 để cung cấp khái niệm điều chỉnh thời gian có thể tùy chỉnh [ví dụ: để tính múi giờ và/hoặc thời gian tiết kiệm ánh sáng ban ngày]lớp ngày giờ. múi giờ
Một lớp triển khai lớp cơ sở trừu tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 dưới dạng phần bù cố định từ UTC
Mới trong phiên bản 3. 2
Các đối tượng của các loại này là bất biến
quan hệ phân lớp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7
Tài sản chung¶
Các loại
import pandas as pd
import numpy as np
import datetime
62, >>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8 có chung những đặc điểm này
Các đối tượng của các loại này là bất biến
Các đối tượng thuộc loại này có thể băm được, nghĩa là chúng có thể được sử dụng làm khóa từ điển
Các đối tượng thuộc loại này hỗ trợ tẩy hiệu quả thông qua mô-đun
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
27
Xác định xem một đối tượng là Aware hay Naive¶
Các đối tượng thuộc loại
import pandas as pd
import numpy as np
import datetime
62 luôn ngây thơMột đối tượng thuộc loại
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 hoặc
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 có thể nhận thức hoặc ngây thơ
Một đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 d nhận biết nếu cả hai điều sau đây đều đúng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
702 không phải là>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
703>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
704 không trả lại>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
703
Mặt khác, d là ngây thơ
Một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 t nhận biết được nếu cả hai điều sau đây đều đúng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
707 không phải là>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
703>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
709 không trả lại>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
703
Nếu không, t là ngây thơ
Sự khác biệt giữa nhận thức và ngây thơ không áp dụng cho các đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
711 Đối tượng¶
Đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 đại diện cho khoảng thời gian, sự khác biệt giữa hai ngày hoặc thời gianlớp ngày giờ. timedelta[ngày=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0]¶
Tất cả các đối số là tùy chọn và mặc định là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'714. Các đối số có thể là số nguyên hoặc số float và có thể dương hoặc âm
Chỉ ngày, giây và micro giây được lưu trữ nội bộ. Các đối số được chuyển đổi thành các đơn vị đó
Một phần nghìn giây được chuyển đổi thành 1000 micro giây
Một phút được chuyển thành 60 giây
Một giờ được chuyển đổi thành 3600 giây
Một tuần được chuyển đổi thành 7 ngày
và ngày, giây và micro giây sau đó được chuẩn hóa để biểu diễn là duy nhất, với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
715>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
716 [số giây trong một ngày]>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
717
Ví dụ sau đây minh họa cách mọi đối số ngoài ngày, giây và micro giây được “hợp nhất” và chuẩn hóa thành ba thuộc tính kết quả đó
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7
Nếu bất kỳ đối số nào là số float và có micro giây phân số, thì micro giây phân số còn lại từ tất cả các đối số sẽ được kết hợp và tổng của chúng được làm tròn đến micro giây gần nhất bằng cách sử dụng bộ ngắt kết nối từ nửa vòng đến chẵn. Nếu không có đối số nào là float, quá trình chuyển đổi và chuẩn hóa là chính xác [không có thông tin nào bị mất]
Nếu giá trị chuẩn hóa của ngày nằm ngoài phạm vi được chỉ định, thì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'718 được tăng lên
Lưu ý rằng việc chuẩn hóa các giá trị âm lúc đầu có thể gây ngạc nhiên. Ví dụ
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'5
Thuộc tính lớp
đồng bằng thời gian. phút ¶Đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 tiêu cực nhất,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'720đồng bằng thời gian. tối đa ¶
Đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 tích cực nhất,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'722đồng bằng thời gian. độ phân giải ¶
Sự khác biệt nhỏ nhất có thể giữa các đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 không bằng nhau,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'724
Lưu ý rằng, do chuẩn hóa, ________ 5725 > ________ 5726.
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'727 không thể biểu diễn dưới dạng đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711
Thuộc tính phiên bản [chỉ đọc]
Thuộc tính
Giá trị
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'729
Giữa -999999999 và bao gồm cả 999999999
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'730
Bao gồm từ 0 đến 86399
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'731
Bao gồm từ 0 đến 999999
hoạt động được hỗ trợ
Hoạt động
Kết quả
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'732
Tổng của t2 và t3. Sau đó t1-t2 == t3 và t1-t3 == t2 là đúng. [1]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'733
Sự khác biệt của t2 và t3. Sau đó t1 == t2 - t3 và t2 == t1 + t3 là đúng. [1][6]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'734
Delta nhân với một số nguyên. Sau đó t1 // i == t2 là đúng, với điều kiện là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'735
Nói chung, t1 * i == t1 * [i-1] + t1 là đúng. [1]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'736
Delta nhân với một số float. Kết quả được làm tròn đến bội số gần nhất của timedelta. độ phân giải sử dụng nửa vòng đến chẵn
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'737
Chia [3] tổng thời lượng t2 cho đơn vị khoảng thời gian t3. Trả về một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'738
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'739
Delta chia cho float hoặc int. Kết quả được làm tròn đến bội số gần nhất của timedelta. độ phân giải sử dụng nửa vòng đến chẵn
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'740 hoặc
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'741
Sàn được tính và phần còn lại [nếu có] bị vứt đi. Trong trường hợp thứ hai, một số nguyên được trả về. [3]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'742
Phần còn lại được tính như một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711. [3]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'744
Tính thương và số dư.
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'745 [3] và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'746. q là một số nguyên và r là một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'748
Trả về một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 có cùng giá trị. [2]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'750
tương đương với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711[-t1. ngày, -t1. giây, -t1. micro giây] và đến t1* -1. [1][4]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'752
tương đương với +t khi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'753 và -t khi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'754. [2]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'755
Trả về một chuỗi ở dạng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'756, trong đó D là số âm cho số âm của
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'757. [5]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'758
Trả về một biểu diễn chuỗi của đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 dưới dạng lệnh gọi hàm tạo với các giá trị thuộc tính chính tắc
ghi chú
Điều này là chính xác nhưng có thể tràn
Điều này là chính xác và không thể tràn
Chia cho 0 tăng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
760-timedelta. max không thể biểu diễn dưới dạng đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
711Biểu diễn chuỗi của đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
711 được chuẩn hóa tương tự như biểu diễn bên trong của chúng. Điều này dẫn đến kết quả hơi bất thường đối với timedelta âm. Ví dụ
20import pandas as pd import numpy as np import datetime
Biểu thức
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
763 sẽ luôn bằng biểu thức>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
764 trừ khi t3 bằng>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
725;
Ngoài các hoạt động được liệt kê ở trên, các đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 hỗ trợ một số phép cộng và phép trừ với các đối tượng
import pandas as pd
import numpy as np
import datetime
62 và >>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 [xem bên dưới]
Đã thay đổi trong phiên bản 3. 2. Phép chia tầng và phép chia thực của đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 cho đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 khác hiện được hỗ trợ, cũng như các phép toán còn lại và hàm
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'771. Phép chia và phép nhân thực của đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 với đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'738 hiện đã được hỗ trợ.
So sánh các đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 được hỗ trợ, với một số lưu ý
Các so sánh
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'775 hoặc
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'776 luôn trả về một
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'777, bất kể loại đối tượng được so sánh
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
Đối với tất cả các phép so sánh khác [chẳng hạn như
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'778 và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'779], khi một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 được so sánh với một đối tượng thuộc loại khác, thì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'781 được nâng lên
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
Trong ngữ cảnh Boolean, một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 được coi là đúng khi và chỉ khi nó không bằng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'783
Phương thức sơ thẩm
đồng bằng thời gian. total_seconds[] ¶Trả về tổng số giây có trong khoảng thời gian. Tương đương với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'784. Đối với các đơn vị khoảng thời gian không phải là giây, hãy sử dụng biểu mẫu chia trực tiếp [e. g.
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'785]
Lưu ý rằng trong khoảng thời gian rất lớn [hơn 270 năm trên hầu hết các nền tảng], phương pháp này sẽ mất độ chính xác micro giây
Mới trong phiên bản 3. 2
Ví dụ về cách sử dụng. >>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
711¶
Một ví dụ bổ sung về chuẩn hóa
import pandas as pd
import numpy as np
import datetime
6Ví dụ về số học
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
4import pandas as pd
import numpy as np
import datetime
62 Đối tượng¶
import pandas as pd
import numpy as np
import datetime
Một đối tượng
import pandas as pd
import numpy as np
import datetime
62 đại diện cho một ngày [năm, tháng và ngày] trong lịch lý tưởng hóa, lịch Gregorian hiện tại được mở rộng vô thời hạn theo cả hai hướngNgày 1 tháng 1 của năm 1 được gọi là ngày 1, ngày 2 tháng 1 của năm 1 được gọi là ngày 2, v.v. 2
lớp ngày giờ. ngày[năm , tháng, day]¶Tất cả các đối số là bắt buộc. Các đối số phải là số nguyên, trong các phạm vi sau
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
790>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
791>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
792
Nếu một đối số nằm ngoài các phạm vi đó được đưa ra, thì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'793 được nêu ra
Các hàm tạo khác, tất cả các phương thức của lớp
phương thức lớp ngày. hôm nay[] ¶Trả về ngày địa phương hiện tại
Điều này tương đương với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'794phương thức lớp ngày. dấu thời gian từ[dấu thời gian] ¶
Trả về ngày địa phương tương ứng với dấu thời gian POSIX, chẳng hạn như được trả về bởi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'795
Điều này có thể tăng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'718, nếu dấu thời gian nằm ngoài phạm vi giá trị được hỗ trợ bởi hàm
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'797 của nền tảng C và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'798 khi lỗi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'797. Điều này thường bị giới hạn trong các năm từ 1970 đến 2038. Lưu ý rằng trên các hệ thống không phải POSIX bao gồm các giây nhuận trong khái niệm dấu thời gian, các giây nhuận bị bỏ qua bởi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'500
Đã thay đổi trong phiên bản 3. 3. Tăng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'718 thay vì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'793 nếu dấu thời gian nằm ngoài phạm vi giá trị được hàm
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'797 nền tảng C hỗ trợ. Tăng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'798 thay vì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'793 khi lỗi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'797. phương thức lớp ngày. từ thứ tự[thứ tự] ¶
Trả về ngày tương ứng với thứ tự Gregorian proleptic, trong đó ngày 1 tháng 1 của năm 1 có thứ tự 1
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'793 được nâng lên trừ khi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'508. Đối với bất kỳ ngày d,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'509phương thức lớp ngày. fromisoformat[date_string] ¶
Trả về một
import pandas as pd
import numpy as np
import datetime
62 tương ứng với một chuỗi_ngày được cung cấp ở bất kỳ định dạng ISO 8601 hợp lệ nào, ngoại trừ các ngày thứ tự [e. g. >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'511]
import pandas as pd
import numpy as np
import datetime
74Mới trong phiên bản 3. 7
Đã thay đổi trong phiên bản 3. 11. Trước đây, phương pháp này chỉ hỗ trợ định dạng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'512. phương thức lớp ngày. từ dương lịch[năm , tuần, day]¶
Trả về một
import pandas as pd
import numpy as np
import datetime
62 tương ứng với ngày theo lịch ISO được chỉ định theo năm, tuần và ngày. Đây là nghịch đảo của hàm >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'514
Mới trong phiên bản 3. 8
Thuộc tính lớp
ngày. phút ¶Ngày đại diện sớm nhất,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'515ngày. tối đa ¶
Ngày đại diện mới nhất,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'516ngày. độ phân giải ¶
Sự khác biệt nhỏ nhất có thể giữa các đối tượng ngày không bằng nhau,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'517
Thuộc tính phiên bản [chỉ đọc]
ngày. năm ¶Bao gồm giữa
import pandas as pd
import numpy as np
import datetime
64 và import pandas as pd
import numpy as np
import datetime
68ngày. tháng ¶Từ 1 đến 12 bao gồm
ngày. ngày ¶Giữa 1 và số ngày trong tháng nhất định của năm nhất định
hoạt động được hỗ trợ
Hoạt động
Kết quả
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'520
date2 sẽ là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'521 ngày sau date1. [1]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'522
Tính date2 sao cho
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'523. [2]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'524
[3]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'525
date1 được coi là nhỏ hơn date2 khi date1 trước date2 về thời gian. [4]
ghi chú
date2 được di chuyển về phía trước theo thời gian nếu
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
526 hoặc lùi lại nếu>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
527. Sau đó>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
528.>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
529 và>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
530 bị bỏ qua.>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
718 được nâng lên nếu>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
532 sẽ nhỏ hơn
64 hoặc lớn hơnimport pandas as pd import numpy as np import datetime
68import pandas as pd import numpy as np import datetime
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
529 và>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
530 bị bỏ quaĐiều này là chính xác và không thể tràn. múi giờ. giây và timedelta. micro giây là 0 và date2 + timedelta == date1 sau
Nói cách khác,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
525 khi và chỉ khi>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
538. So sánh ngày tăng>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
781 nếu đối tượng so sánh khác không phải là đối tượng
62. Tuy nhiên, thay vào đó,import pandas as pd import numpy as np import datetime
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
541 được trả về nếu đối tượng so sánh khác có thuộc tính>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
542. Móc này cung cấp cho các loại đối tượng ngày khác cơ hội thực hiện so sánh kiểu hỗn hợp. Nếu không, khi một đối tượng
62 được so sánh với một đối tượng thuộc loại khác,import pandas as pd import numpy as np import datetime
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
781 được nâng lên trừ khi so sánh là>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
775 hoặc>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
776. Các trường hợp sau lần lượt trả về>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
547 hoặc>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
548
Trong ngữ cảnh Boolean, tất cả các đối tượng
import pandas as pd
import numpy as np
import datetime
62 được coi là đúngPhương thức sơ thẩm
ngày. thay thế[năm=chính mình. năm , tháng=mình. tháng , ngày=chính mình. ngày] ¶Trả về một ngày có cùng giá trị, ngoại trừ các tham số được cung cấp giá trị mới theo bất kỳ đối số từ khóa nào được chỉ định
Ví dụ
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'2
Trả lại một
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'550 chẳng hạn như trả về bởi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'551
Giờ, phút và giây là 0 và cờ DST là -1
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'552 tương đương với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'70
trong đó
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'553 là số ngày trong năm hiện tại bắt đầu bằng
import pandas as pd
import numpy as np
import datetime
65 cho ngày 1 tháng 1ngày. bình thường[] ¶Trả về thứ tự Gregorian proleptic của ngày, trong đó ngày 1 tháng 1 của năm 1 có thứ tự 1. Đối với bất kỳ đối tượng
import pandas as pd
import numpy as np
import datetime
62 d, >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'509ngày. ngày trong tuần[] ¶
Trả về ngày trong tuần dưới dạng số nguyên, trong đó Thứ Hai là 0 và Chủ Nhật là 6. Ví dụ:
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'557, Thứ Tư. Xem thêm
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'558ngày. ngày trong tuần[] ¶
Trả về ngày trong tuần dưới dạng số nguyên, trong đó Thứ Hai là 1 và Chủ Nhật là 7. Ví dụ:
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'559, Thứ Tư. Xem thêm
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'560,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'561ngày. isocalendar[] ¶
Trả về đối tượng tuple có tên có ba thành phần.
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
41, >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'563 và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'564.
Lịch ISO là một biến thể được sử dụng rộng rãi của lịch Gregorian. 3
Năm ISO bao gồm 52 hoặc 53 tuần đầy đủ và trong đó một tuần bắt đầu vào Thứ Hai và kết thúc vào Chủ nhật. Tuần đầu tiên của một năm ISO là tuần dương lịch [Gregorian] đầu tiên của một năm có ngày thứ Năm. Đây được gọi là tuần số 1 và năm ISO của ngày thứ Năm đó giống với năm Gregorian của nó
Ví dụ: năm 2004 bắt đầu vào Thứ Năm, vì vậy tuần đầu tiên của năm ISO 2004 bắt đầu vào Thứ Hai, ngày 29 tháng 12 năm 2003 và kết thúc vào Chủ Nhật, ngày 4 tháng 1 năm 2004
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'71
Đã thay đổi trong phiên bản 3. 9. Kết quả thay đổi từ một bộ thành bộ có tên .
ngày. isoformat[] ¶Trả về một chuỗi đại diện cho ngày ở định dạng ISO 8601,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'512
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'72ngày. __str__[] ¶
Đối với một ngày d,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'566 tương đương với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'567ngày. thời gian[] ¶
Trả về một chuỗi đại diện cho ngày
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'73
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'568 tương đương với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'74
trên các nền tảng có chức năng C
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'569 gốc [mà
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'570 gọi, nhưng mà
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'571 không gọi] phù hợp với tiêu chuẩn Cngày. thời gian strf[định dạng] ¶
Trả về một chuỗi đại diện cho ngày, được kiểm soát bởi một chuỗi định dạng rõ ràng. Mã định dạng đề cập đến giờ, phút hoặc giây sẽ thấy 0 giá trị. Để biết danh sách đầy đủ các lệnh định dạng, hãy xem strftime[] và strptime[] Hành vi .
ngày. __format__[định dạng] ¶Giống như
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'572. Điều này giúp có thể chỉ định chuỗi định dạng cho đối tượng
import pandas as pd
import numpy as np
import datetime
62 trong ký tự chuỗi được định dạng và khi sử dụng >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'574. Để biết danh sách đầy đủ các lệnh định dạng, hãy xem strftime[] và strptime[] Hành vi .
Ví dụ về cách sử dụng. import pandas as pd
import numpy as np
import datetime
62¶
import pandas as pd
import numpy as np
import datetime
Ví dụ về đếm số ngày đến một sự kiện
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'75
Thêm ví dụ về cách làm việc với
import pandas as pd
import numpy as np
import datetime
62>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'76
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 Đối tượng¶
Đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 là một đối tượng duy nhất chứa tất cả thông tin từ đối tượng
import pandas as pd
import numpy as np
import datetime
62 và đối tượng >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0
Giống như một đối tượng
import pandas as pd
import numpy as np
import datetime
62, >>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 giả sử lịch Gregorian hiện tại được mở rộng theo cả hai hướng;
Người xây dựng
lớp ngày giờ. ngày giờ[năm , tháng, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0]¶Các đối số năm, tháng và ngày là bắt buộc. tzinfo có thể là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703 hoặc một thể hiện của lớp con
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4. Các đối số còn lại phải là số nguyên trong các phạm vi sau
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
790,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
791,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
792,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
590,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
591,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
592,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
593,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
594
Nếu một đối số nằm ngoài các phạm vi đó được đưa ra, thì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'793 được nêu ra
Mới trong phiên bản 3. 6. Đã thêm đối số
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'596.
Các hàm tạo khác, tất cả các phương thức của lớp
phương thức lớp ngày giờ. hôm nay[] ¶Trả về ngày giờ địa phương hiện tại, với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703
Tương đương với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'77
Xem thêm
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'599,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'500
Phương thức này có chức năng tương đương với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'599, nhưng không có tham số
import pandas as pd
import numpy as np
import datetime
2002phương thức lớp ngày giờ. bây giờ[tz=Không]¶Trả về ngày và giờ địa phương hiện tại
Nếu đối số tùy chọn tz là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703 hoặc không được chỉ định, thì điều này giống như
import pandas as pd
import numpy as np
import datetime
2004, nhưng, nếu có thể, cung cấp độ chính xác cao hơn mức có thể nhận được khi đi qua dấu thời gian >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'795 [ví dụ: điều này có thể thực hiện được trên các nền tảng cung cấp hàm C
import pandas as pd
import numpy as np
import datetime
2006]Nếu tz không phải là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703, thì nó phải là một thể hiện của lớp con
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 và ngày giờ hiện tại được chuyển đổi thành múi giờ của tz
Chức năng này được ưa thích hơn
import pandas as pd
import numpy as np
import datetime
2004 và import pandas as pd
import numpy as np
import datetime
2010phương thức lớp ngày giờ. utcnow[] ¶Trả về ngày và giờ UTC hiện tại, với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703
Điều này giống như
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'599, nhưng trả về ngày và giờ UTC hiện tại, dưới dạng một đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 ngây thơ. Có thể nhận được thời gian UTC hiện tại đã biết bằng cách gọi
import pandas as pd
import numpy as np
import datetime
2015. Xem thêm >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'599
Cảnh báo
Bởi vì các đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 ngây thơ được nhiều phương thức
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 coi là giờ địa phương, nên sử dụng thời gian nhận thức để biểu thị thời gian trong UTC. Như vậy, cách được đề xuất để tạo một đối tượng biểu thị thời gian hiện tại theo UTC là gọi số
import pandas as pd
import numpy as np
import datetime
2015phương thức lớp ngày giờ. dấu thời gian từ[dấu thời gian , tz=None]¶Trả về ngày và giờ địa phương tương ứng với dấu thời gian POSIX, chẳng hạn như được trả về bởi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'795. Nếu đối số tùy chọn tz là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703 hoặc không được chỉ định, thì dấu thời gian được chuyển đổi thành ngày giờ địa phương của nền tảng và đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 được trả về là ngây thơ
Nếu tz không phải là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703, thì nó phải là một thể hiện của lớp con
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 và dấu thời gian được chuyển đổi thành múi giờ của tz
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'500 có thể tăng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'718, nếu dấu thời gian nằm ngoài phạm vi giá trị được hỗ trợ bởi các hàm C
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'797 hoặc
import pandas as pd
import numpy as np
import datetime
2028 của nền tảng và >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'798 khi lỗi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'797 hoặc
import pandas as pd
import numpy as np
import datetime
2028. Điều này thường bị giới hạn trong các năm từ 1970 đến 2038. Lưu ý rằng trên các hệ thống không phải POSIX bao gồm các giây nhuận trong khái niệm dấu thời gian của chúng, các giây nhuận bị bỏ qua bởi >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'500 và sau đó có thể có hai dấu thời gian khác nhau một giây mang lại các đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 giống hệt nhau. Phương pháp này được ưa thích hơn
import pandas as pd
import numpy as np
import datetime
2034Đã thay đổi trong phiên bản 3. 3. Tăng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'718 thay vì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'793 nếu dấu thời gian nằm ngoài phạm vi giá trị được hỗ trợ bởi các hàm nền tảng C
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'797 hoặc
import pandas as pd
import numpy as np
import datetime
2028. Tăng >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'798 thay vì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'793 khi thất bại
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'797 hoặc
import pandas as pd
import numpy as np
import datetime
2028. Đã thay đổi trong phiên bản 3. 6. ______7500 có thể trả về các phiên bản với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'596 được đặt thành 1. phương thức lớp ngày giờ. utcfromtimestamp[dấu thời gian] ¶
Trả về UTC
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 tương ứng với dấu thời gian POSIX, với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703. [Đối tượng kết quả là ngây thơ. ]
This may raise
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'718, if the timestamp is out of the range of values supported by the platform C
import pandas as pd
import numpy as np
import datetime
2028 function, and >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'798 on
import pandas as pd
import numpy as np
import datetime
2028 failure. Điều này thường bị giới hạn trong các năm từ 1970 đến 2038Để có được một đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 nhận biết, hãy gọi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'500
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'78
Trên nền tảng tuân thủ POSIX, nó tương đương với biểu thức sau
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'79
ngoại trừ công thức sau luôn hỗ trợ phạm vi năm đầy đủ. giữa
import pandas as pd
import numpy as np
import datetime
64 và bao gồm cả import pandas as pd
import numpy as np
import datetime
68Cảnh báo
Bởi vì các đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 ngây thơ được nhiều phương thức
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 coi là giờ địa phương, nên sử dụng thời gian nhận thức để biểu thị thời gian trong UTC. Do đó, cách được đề xuất để tạo một đối tượng đại diện cho một dấu thời gian cụ thể trong UTC là gọi số
import pandas as pd
import numpy as np
import datetime
2058Đã thay đổi trong phiên bản 3. 3. Tăng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'718 thay vì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'793 nếu dấu thời gian nằm ngoài phạm vi giá trị được hàm
import pandas as pd
import numpy as np
import datetime
2028 nền tảng C hỗ trợ. Tăng >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'798 thay vì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'793 khi lỗi
import pandas as pd
import numpy as np
import datetime
2028. classmethod datetime. fromordinal[ordinal] ¶Trả về
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 tương ứng với thứ tự Gregorian tiên sinh, trong đó ngày 1 tháng 1 của năm 1 có thứ tự 1.
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'793 is raised unless
import pandas as pd
import numpy as np
import datetime
2067. The hour, minute, second and microsecond of the result are all 0, and >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 is
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703classmethod datetime. kết hợp[ngày , thời gian . tzinfo, tzinfo=self.tzinfo] ¶
Return a new
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 object whose date components are equal to the given
import pandas as pd
import numpy as np
import datetime
62 object’s, and whose time components are equal to the given >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object’s. If the tzinfo argument is provided, its value is used to set the
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 attribute of the result, otherwise the
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 attribute of the time argument is used
For any
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 object d,
import pandas as pd
import numpy as np
import datetime
2076. If date is a >>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 object, its time components and
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 attributes are ignored
Changed in version 3. 6. Added the tzinfo argument.
classmethod datetime. fromisoformat[date_string] ¶Return a
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 corresponding to a date_string in any valid ISO 8601 format, with the following exceptions
Time zone offsets may have fractional seconds
The
2080 separator may be replaced by any single unicode characterimport pandas as pd import numpy as np import datetime
Ordinal dates are not currently supported
Giờ và phút phân số không được hỗ trợ
Examples
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'50
Mới trong phiên bản 3. 7
Changed in version 3. 11. Previously, this method only supported formats that could be emitted by
import pandas as pd
import numpy as np
import datetime
2081 or import pandas as pd
import numpy as np
import datetime
2082. classmethod datetime. fromisocalendar[year , week , day] ¶Return a
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 corresponding to the ISO calendar date specified by year, week and day. The non-date components of the datetime are populated with their normal default values. This is the inverse of the function
import pandas as pd
import numpy as np
import datetime
2084Mới trong phiên bản 3. 8
classmethod datetime. strptime[date_string , format] ¶Return a
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 corresponding to date_string, parsed according to format
This is equivalent to
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'51
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'793 is raised if the date_string and format can’t be parsed by
import pandas as pd
import numpy as np
import datetime
2087 or if it returns a value which isn’t a time tuple. For a complete list of formatting directives, see strftime[] and strptime[] Behavior . Thuộc tính lớp
datetime. min ¶The earliest representable
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7,
import pandas as pd
import numpy as np
import datetime
2089datetime. max ¶The latest representable
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7,
import pandas as pd
import numpy as np
import datetime
2091datetime. resolution ¶The smallest possible difference between non-equal
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 objects,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'724
Thuộc tính phiên bản [chỉ đọc]
datetime. năm ¶Bao gồm giữa
import pandas as pd
import numpy as np
import datetime
64 và import pandas as pd
import numpy as np
import datetime
68datetime. month ¶Từ 1 đến 12 bao gồm
datetime. day ¶Giữa 1 và số ngày trong tháng nhất định của năm nhất định
datetime. hour ¶In
import pandas as pd
import numpy as np
import datetime
2096ngày giờ. minute ¶In
import pandas as pd
import numpy as np
import datetime
2097datetime. second ¶In
import pandas as pd
import numpy as np
import datetime
2097datetime. micro giây ¶Trong
import pandas as pd
import numpy as np
import datetime
2099datetime. tzinfo ¶Đối tượng được truyền dưới dạng đối số tzinfo cho hàm tạo
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 hoặc
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703 nếu không có đối số nào được truyềndatetime. fold ¶
Trong
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False02. Used to disambiguate wall times during a repeated interval. [A repeated interval occurs when clocks are rolled back at the end of daylight saving time or when the UTC offset for the current zone is decreased for political reasons. ] The value 0 [1] represents the earlier [later] of the two moments with the same wall time representation
New in version 3. 6
hoạt động được hỗ trợ
Hoạt động
Kết quả
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False03
[1]
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False04
[2]
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False05
[3]
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False06
Compares
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 to
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7. [4]
datetime2 is a duration of timedelta removed from datetime1, moving forward in time if
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
521 > 0, or backward if>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
521 < 0. The result has the same>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attribute as the input datetime, and datetime2 - datetime1 == timedelta after.>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
718 is raised if datetime2. year would be smaller than
64 or larger thanimport pandas as pd import numpy as np import datetime
68. Note that no time zone adjustments are done even if the input is an aware objectimport pandas as pd import numpy as np import datetime
Computes the datetime2 such that datetime2 + timedelta == datetime1. As for addition, the result has the same
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attribute as the input datetime, and no time zone adjustments are done even if the input is awareSubtraction of a
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
7 from a>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
7 is defined only if both operands are naive, or if both are aware. If one is aware and the other is naive,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
781 is raisedIf both are naive, or both are aware and have the same
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attribute, the>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attributes are ignored, and the result is a>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
711 object t such that>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
22. No time zone adjustments are done in this caseIf both are aware and have different
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attributes,>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
24 acts as if a and b were first converted to naive UTC datetimes first. The result is>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
25 except that the implementation never overflowsdatetime1 is considered less than datetime2 when datetime1 precedes datetime2 in time
If one comparand is naive and the other is aware,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
781 is raised if an order comparison is attempted. For equality comparisons, naive instances are never equal to aware instancesIf both comparands are aware, and have the same
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attribute, the common>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attribute is ignored and the base datetimes are compared. If both comparands are aware and have different>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attributes, the comparands are first adjusted by subtracting their UTC offsets [obtained from>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
30]Changed in version 3. 3. Equality comparisons between aware and naive
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
7 instances don’t raise>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
781.Note
In order to stop comparison from falling back to the default scheme of comparing object addresses, datetime comparison normally raises
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
781 if the other comparand isn’t also a>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
7 object. Tuy nhiên, thay vào đó,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
541 được trả về nếu đối tượng so sánh khác có thuộc tính>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
542. This hook gives other kinds of date objects a chance at implementing mixed-type comparison. Nếu không, khi một đối tượng>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
7 được so sánh với một đối tượng thuộc loại khác, thì>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
781 sẽ được nâng lên trừ khi so sánh là>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
775 hoặc>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
776. The latter cases return>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
547 or>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
548, respectively
Phương thức sơ thẩm
datetime. date[] ¶Return
import pandas as pd
import numpy as np
import datetime
62 object with same year, month and daydatetime. thời gian[] ¶Return
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object with same hour, minute, second, microsecond and fold.
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 is
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703. Xem thêm phương pháp
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False47
Changed in version 3. 6. The fold value is copied to the returned
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object. ngày giờ. timetz[] ¶
Return
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object with same hour, minute, second, microsecond, fold, and tzinfo attributes. See also method
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False50
Changed in version 3. 6. The fold value is copied to the returned
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object. datetime. replace[year=self. year , month=self. month , day=self. day , hour=self. hour , minute=self. minute , second=self. second , microsecond=self. microsecond , tzinfo=self. tzinfo , * , fold=0] ¶
Return a datetime with the same attributes, except for those attributes given new values by whichever keyword arguments are specified. Note that
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False52 can be specified to create a naive datetime from an aware datetime with no conversion of date and time data
Mới trong phiên bản 3. 6. Đã thêm đối số
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'596. datetime. astimezone[tz=None] ¶
Return a
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 object with new
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 attribute tz, adjusting the date and time data so the result is the same UTC time as self, but in tz’s local time
If provided, tz must be an instance of a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclass, and its
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False57 and
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False58 methods must not return
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703. If self is naive, it is presumed to represent time in the system timezone
If called without arguments [or with
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False60] the system local timezone is assumed for the target timezone. The
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False61 attribute of the converted datetime instance will be set to an instance of
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8 with the zone name and offset obtained from the OS
If
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False63 is tz,
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False64 is equal to self. no adjustment of date or time data is performed. Else the result is local time in the timezone tz, representing the same UTC time as self. after
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False65,
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False66 will have the same date and time data as
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False67
If you merely want to attach a time zone object tz to a datetime dt without adjustment of date and time data, use
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False68. If you merely want to remove the time zone object from an aware datetime dt without conversion of date and time data, use
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False69
Note that the default
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False70 method can be overridden in a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclass to affect the result returned by
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False72. Ignoring error cases,
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False72 acts like
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'52
Changed in version 3. 3. tz now can be omitted.
Changed in version 3. 6. The
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False72 method can now be called on naive instances that are presumed to represent system local time. datetime. utcoffset[] ¶
If
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 is
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703, returns
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703, else returns
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False78, and raises an exception if the latter doesn’t return
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703 or a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 object with magnitude less than one day
Changed in version 3. 7. The UTC offset is not restricted to a whole number of minutes.
datetime. dst[] ¶If
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 is
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703, returns
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703, else returns
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False84, and raises an exception if the latter doesn’t return
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703 or a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 object with magnitude less than one day
Changed in version 3. 7. The DST offset is not restricted to a whole number of minutes.
datetime. tzname[] ¶Nếu
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703, trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703, ngược lại trả về
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False90, đưa ra một ngoại lệ nếu cái sau không trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703 hoặc một đối tượng chuỗi,datetime. timetuple[] ¶
Trả lại một
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'550 chẳng hạn như trả về bởi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'551
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'552 tương đương với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'53
where
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'553 is the day number within the current year starting with
import pandas as pd
import numpy as np
import datetime
65 for January 1st. The >>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False97 flag of the result is set according to the
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False58 method.
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 is
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703 or
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False58 returns
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703,
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False97 is set to
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'04; else if
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False58 returns a non-zero value,
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False97 is set to
import pandas as pd
import numpy as np
import datetime
65; else >>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False97 is set to
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'714datetime. utctimetuple[] ¶
If
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 instance d is naive, this is the same as
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'552 except that
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False97 is forced to 0 regardless of what
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'13 returns. DST is never in effect for a UTC time
If d is aware, d is normalized to UTC time, by subtracting
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'14, and a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'550 for the normalized time is returned.
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False97 is forced to 0. Note that an
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'718 may be raised if d. year was
import pandas as pd
import numpy as np
import datetime
64 or import pandas as pd
import numpy as np
import datetime
68 and UTC adjustment spills over a year boundaryCảnh báo
Because naive
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 objects are treated by many
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 methods as local times, it is preferred to use aware datetimes to represent times in UTC; as a result, using
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'22 may give misleading results. If you have a naive
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 representing UTC, use
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'24 to make it aware, at which point you can use
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'25datetime. toordinal[] ¶
Return the proleptic Gregorian ordinal of the date. The same as
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'26datetime. timestamp[] ¶
Return POSIX timestamp corresponding to the
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 instance. The return value is a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'738 similar to that returned by
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'795
Naive
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 instances are assumed to represent local time and this method relies on the platform C
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'31 function to perform the conversion. Since
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 supports wider range of values than
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'31 on many platforms, this method may raise
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'718 for times far in the past or far in the future
For aware
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 instances, the return value is computed as
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'54
New in version 3. 3
Changed in version 3. 6. The
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'36 method uses the
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'596 attribute to disambiguate the times during a repeated interval.
Note
There is no method to obtain the POSIX timestamp directly from a naive
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 instance representing UTC time. If your application uses this convention and your system timezone is not set to UTC, you can obtain the POSIX timestamp by supplying
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'39
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'55
or by calculating the timestamp directly
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'56datetime. weekday[] ¶
Return the day of the week as an integer, where Monday is 0 and Sunday is 6. The same as
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'40. See also
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'558datetime. isoweekday[] ¶
Return the day of the week as an integer, where Monday is 1 and Sunday is 7. The same as
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'42. See also
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'560,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'561datetime. isocalendar[] ¶
Trả về một bộ có tên với ba thành phần.
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
41, >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'563 and
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'564. The same as
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'48. datetime. isoformat[sep=', timespec='auto']¶
Return a string representing the date and time in ISO 8601 format
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
49, if
47 is not 0raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
51, if
47 is 0raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
If
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False57 does not return
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703, a string is appended, giving the UTC offset
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
55, if
47 is not 0raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
57, if
47 is 0raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
Examples
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'57
The optional argument sep [default
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'59] is a one-character separator, placed between the date and time portions of the result. For example
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'58
The optional argument timespec specifies the number of additional components of the time to include [the default is
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'60]. It can be one of the following
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
60. Same as>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
62 if
47 is 0, same asraw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
64 otherwise>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
65. Include the
44 in the two-digitraw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
67 format>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
68. Include
44 andraw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
45 inraw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
71 format>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
62. Include
44,raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
45, andraw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
46 inraw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
76 format>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
77. Include full time, but truncate fractional second part to milliseconds.>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
78 format>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
64. Include full time in>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
80 format
Note
Excluded time components are truncated, not rounded
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'793 will be raised on an invalid timespec argument
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'59
New in version 3. 6. Added the timespec argument.
datetime. __str__[] ¶For a
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 instance d,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'566 is equivalent to
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'84datetime. ctime[] ¶
Return a string representing the date and time
import pandas as pd
import numpy as np
import datetime
200The output string will not include time zone information, regardless of whether the input is aware or naive
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'568 tương đương với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'74
on platforms where the native C
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'569 function [which
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'570 invokes, but which
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'88 does not invoke] conforms to the C standarddatetime. strftime[format] ¶
Return a string representing the date and time, controlled by an explicit format string. For a complete list of formatting directives, see strftime[] and strptime[] Behavior .
datetime. __format__[format] ¶Same as
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'89. This makes it possible to specify a format string for a
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 object in formatted string literals and when using
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'574. For a complete list of formatting directives, see strftime[] and strptime[] Behavior .
Examples of Usage. >>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7¶
Examples of working with
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 objects
import pandas as pd
import numpy as np
import datetime
202The example below defines a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclass capturing time zone information for Kabul, Afghanistan, which used +4 UTC until 1945 and then +4. 30 UTC thereafter
import pandas as pd
import numpy as np
import datetime
203Usage of
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'95 from above
import pandas as pd
import numpy as np
import datetime
204>>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 Objects¶
A
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object represents a [local] time of day, independent of any particular day, and subject to adjustment via a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 objectclass datetime. time[hour=0 , minute=0 , second=0 , microsecond=0 , tzinfo=None , * , fold=0] ¶
All arguments are optional. tzinfo may be
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703, or an instance of a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclass. The remaining arguments must be integers in the following ranges
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
590,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
591,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
592,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
593,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
594
If an argument outside those ranges is given,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'793 is raised. All default to
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'714 except tzinfo, which defaults to
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703
Thuộc tính lớp
time. min ¶The earliest representable
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0,
import pandas as pd
import numpy as np
import datetime
610time. max ¶The latest representable
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0,
import pandas as pd
import numpy as np
import datetime
612time. resolution ¶The smallest possible difference between non-equal
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 objects,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'724, although note that arithmetic on
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 objects is not supported
Thuộc tính phiên bản [chỉ đọc]
time. hour ¶In
import pandas as pd
import numpy as np
import datetime
2096time. minute ¶In
import pandas as pd
import numpy as np
import datetime
2097time. second ¶In
import pandas as pd
import numpy as np
import datetime
2097time. microsecond ¶Trong
import pandas as pd
import numpy as np
import datetime
2099time. tzinfo ¶The object passed as the tzinfo argument to the
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 constructor, or
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703 if none was passedtime. fold ¶
Trong
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False02. Used to disambiguate wall times during a repeated interval. [A repeated interval occurs when clocks are rolled back at the end of daylight saving time or when the UTC offset for the current zone is decreased for political reasons. ] The value 0 [1] represents the earlier [later] of the two moments with the same wall time representation
New in version 3. 6
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 objects support comparison of
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 to
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0, where a is considered less than b when a precedes b in time. If one comparand is naive and the other is aware,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'781 is raised if an order comparison is attempted. For equality comparisons, naive instances are never equal to aware instances
If both comparands are aware, and have the same
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 attribute, the common
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 attribute is ignored and the base times are compared. If both comparands are aware and have different
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 attributes, the comparands are first adjusted by subtracting their UTC offsets [obtained from
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False30]. In order to stop mixed-type comparisons from falling back to the default comparison by object address, when a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object is compared to an object of a different type,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'781 is raised unless the comparison is
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'775 or
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'776. The latter cases return
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'547 or
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'548, respectively
Changed in version 3. 3. Equality comparisons between aware and naive
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 instances don’t raise
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'781.
In Boolean contexts, a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object is always considered to be true
Changed in version 3. 5. Before Python 3. 5, a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object was considered to be false if it represented midnight in UTC. Hành vi này được coi là tối nghĩa và dễ bị lỗi và đã bị xóa trong Python 3. 5. See bpo-13936 for full details.
nhà xây dựng khác
phương pháp phân loại thời gian. fromisoformat[time_string] ¶Return a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 corresponding to a time_string in any valid ISO 8601 format, with the following exceptions
Time zone offsets may have fractional seconds
The leading
2080, normally required in cases where there may be ambiguity between a date and a time, is not requiredimport pandas as pd import numpy as np import datetime
Fractional seconds may have any number of digits [anything beyond 6 will be truncated]
Giờ và phút phân số không được hỗ trợ
Examples
import pandas as pd
import numpy as np
import datetime
205Mới trong phiên bản 3. 7
Changed in version 3. 11. Previously, this method only supported formats that could be emitted by
import pandas as pd
import numpy as np
import datetime
643. Phương thức sơ thẩm
time. replace[hour=self. hour , minute=self. minute , second=self. second , microsecond=self. microsecond , tzinfo=self. tzinfo , * , fold=0] ¶Return a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 with the same value, except for those attributes given new values by whichever keyword arguments are specified. Note that
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False52 can be specified to create a naive
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 from an aware
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0, without conversion of the time data
Mới trong phiên bản 3. 6. Đã thêm đối số
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'596. time. isoformat[timespec='auto'] ¶
Return a string representing the time in ISO 8601 format, one of
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
80, if
47 is not 0raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
76, if
47 is 0raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
653, ifimport pandas as pd import numpy as np import datetime
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
57 does not return>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
703
656, ifimport pandas as pd import numpy as np import datetime
47 is 0 andraw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
57 does not return>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
703
The optional argument timespec specifies the number of additional components of the time to include [the default is
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'60]. It can be one of the following
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
60. Same as>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
62 if
47 is 0, same asraw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
64 otherwise>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
65. Include the
44 in the two-digitraw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
67 format>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
68. Include
44 andraw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
45 inraw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
71 format>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
62. Include
44,raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
45, andraw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
46 inraw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
76 format>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
77. Include full time, but truncate fractional second part to milliseconds.>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
78 format>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
64. Include full time in>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
80 format
Note
Excluded time components are truncated, not rounded
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'793 will be raised on an invalid timespec argument
Ví dụ
import pandas as pd
import numpy as np
import datetime
206New in version 3. 6. Added the timespec argument.
time. __str__[] ¶For a time t,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'755 is equivalent to
import pandas as pd
import numpy as np
import datetime
683time. strftime[format] ¶Return a string representing the time, controlled by an explicit format string. For a complete list of formatting directives, see strftime[] and strptime[] Behavior .
time. __format__[format] ¶Same as
import pandas as pd
import numpy as np
import datetime
684. This makes it possible to specify a format string for a >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object in formatted string literals and when using
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'574. For a complete list of formatting directives, see strftime[] and strptime[] Behavior . time. utcoffset[] ¶
Nếu
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703, trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703, ngược lại trả về
import pandas as pd
import numpy as np
import datetime
690 và đưa ra một ngoại lệ nếu cái sau không trả về >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703 hoặc một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 có cường độ nhỏ hơn một ngày
Changed in version 3. 7. The UTC offset is not restricted to a whole number of minutes.
time. dst[] ¶If
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 is
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703, returns
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703, else returns
import pandas as pd
import numpy as np
import datetime
696, and raises an exception if the latter doesn’t return >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703, or a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 object with magnitude less than one day
Changed in version 3. 7. The DST offset is not restricted to a whole number of minutes.
time. tzname[] ¶If
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 is
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703, returns
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703, else returns
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
402, or raises an exception if the latter doesn’t return >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703 or a string object
Examples of Usage. >>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0¶
Examples of working with a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object
import pandas as pd
import numpy as np
import datetime
207>>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 Objects¶
class datetime. tzinfo ¶This is an abstract base class, meaning that this class should not be instantiated directly. Define a subclass of
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 to capture information about a particular time zone
An instance of [a concrete subclass of]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 can be passed to the constructors for
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 and
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 objects. The latter objects view their attributes as being in local time, and the
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 object supports methods revealing offset of local time from UTC, the name of the time zone, and DST offset, all relative to a date or time object passed to them
You need to derive a concrete subclass, and [at least] supply implementations of the standard
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 methods needed by the
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 methods you use. The
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 module provides
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8, a simple concrete subclass of
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 which can represent timezones with fixed offset from UTC such as UTC itself or North American EST and EDT
Special requirement for pickling. A
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclass must have an
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
418 method that can be called with no arguments, otherwise it can be pickled but possibly not unpickled again. This is a technical requirement that may be relaxed in the futureA concrete subclass of
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 may need to implement the following methods. Exactly which methods are needed depends on the uses made of aware
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 objects. If in doubt, simply implement all of themtzinfo. utcoffset[dt] ¶
Return offset of local time from UTC, as a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 object that is positive east of UTC. If local time is west of UTC, this should be negative
This represents the total offset from UTC; for example, if a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 object represents both time zone and DST adjustments,
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False57 should return their sum. If the UTC offset isn’t known, return
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703. Else the value returned must be a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 object strictly between
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
426 and raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
427 [the magnitude of the offset must be less than one day]. Most implementations of >>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False57 will probably look like one of these two
import pandas as pd
import numpy as np
import datetime
208If
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False57 does not return
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703,
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False58 should not return
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703 either
The default implementation of
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False57 raises
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
434Changed in version 3. 7. The UTC offset is not restricted to a whole number of minutes.
tzinfo. dst[dt] ¶Return the daylight saving time [DST] adjustment, as a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 object or
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703 if DST information isn’t known
Return
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'783 if DST is not in effect. If DST is in effect, return the offset as a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 object [see
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False57 for details]. Note that DST offset, if applicable, has already been added to the UTC offset returned by
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False57, so there’s no need to consult
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False58 unless you’re interested in obtaining DST info separately. For example,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'25 calls its
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 attribute’s
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False58 method to determine how the
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False97 flag should be set, and
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False70 calls
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False58 to account for DST changes when crossing time zones
An instance tz of a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclass that models both standard and daylight times must be consistent in this sense
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
449must return the same result for every
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 dt with
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
451 For sane >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclasses, this expression yields the time zone’s “standard offset”, which should not depend on the date or the time, but only on geographic location. The implementation of
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
453 relies on this, but cannot detect violations; it’s the programmer’s responsibility to ensure it. If a >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclass cannot guarantee this, it may be able to override the default implementation of
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False70 to work correctly with
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False72 regardless
Most implementations of
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False58 will probably look like one of these two
import pandas as pd
import numpy as np
import datetime
209or
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False0
The default implementation of
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False58 raises
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
434Changed in version 3. 7. The DST offset is not restricted to a whole number of minutes.
tzinfo. tzname[dt] ¶Return the time zone name corresponding to the
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 object dt, as a string. Nothing about string names is defined by the
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 module, and there’s no requirement that it mean anything in particular. For example, “GMT”, “UTC”, “-500”, “-5. 00”, “EDT”, “US/Eastern”, “America/New York” are all valid replies. Return
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703 if a string name isn’t known. Note that this is a method rather than a fixed string primarily because some
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclasses will wish to return different names depending on the specific value of dt passed, especially if the
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 class is accounting for daylight time
The default implementation of
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
465 raises raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
434Các phương thức này được gọi bởi một đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 hoặc
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0, để đáp lại các phương thức cùng tên của chúng. A
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 object passes itself as the argument, and a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object passes
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703 as the argument. A
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclass’s methods should therefore be prepared to accept a dt argument of
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703, or of class
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7
When
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703 is passed, it’s up to the class designer to decide the best response. Ví dụ: trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703 là phù hợp nếu lớp muốn nói rằng các đối tượng thời gian không tham gia vào các giao thức
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4. It may be more useful for
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
478 to return the standard UTC offset, as there is no other convention for discovering the standard offsetKhi một đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 được truyền để phản hồi một phương thức
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7, thì
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
481 chính là đối tượng như self. >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 methods can rely on this, unless user code calls
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 methods directly. Mục đích là các phương thức
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 diễn giải dt theo giờ địa phương và không cần lo lắng về các đối tượng ở các múi giờ khác
There is one more
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 method that a subclass may wish to overridetzinfo. từutc[dt] ¶
Điều này được gọi từ triển khai
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
453 mặc định. Khi được gọi từ đó, raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
481 là chính nó và dữ liệu ngày và giờ của dt sẽ được xem là thể hiện thời gian UTC. Mục đích của raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
488 là điều chỉnh dữ liệu ngày và giờ, trả về một ngày giờ tương đương theo giờ địa phương của chính bạnHầu hết các lớp con của
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 sẽ có thể kế thừa triển khai
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
488 mặc định mà không gặp sự cố. Nó đủ mạnh để xử lý các múi giờ có độ lệch cố định và các múi giờ tính cả thời gian tiêu chuẩn và thời gian ban ngày và cả thời gian sau ngay cả khi thời gian chuyển đổi DST khác nhau trong các năm khác nhau. Một ví dụ về múi giờ mà việc triển khai raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
488 mặc định có thể không xử lý chính xác trong mọi trường hợp là trường hợp mà phần bù tiêu chuẩn [từ UTC] phụ thuộc vào ngày và giờ cụ thể đã trôi qua, điều này có thể xảy ra vì lý do chính trị. Việc triển khai mặc định của >>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False72 và
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
488 có thể không tạo ra kết quả như bạn muốn nếu kết quả là một trong những giờ diễn ra vào thời điểm bù trừ tiêu chuẩn thay đổiBỏ qua mã cho các trường hợp lỗi, việc triển khai
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
488 mặc định hoạt động như>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False1
Trong tệp
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
495 sau đây có một số ví dụ về lớp >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False2
Lưu ý rằng có những sự tinh tế không thể tránh khỏi hai lần mỗi năm trong phân lớp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 chiếm cả thời gian tiêu chuẩn và thời gian ban ngày, tại các điểm chuyển tiếp DST. Để cụ thể, hãy xem xét Miền Đông Hoa Kỳ [UTC -0500], nơi EDT bắt đầu sau 1 phút. 59 [EST] vào Chủ nhật thứ hai của tháng 3 và kết thúc vào phút sau 1. 59 [EDT] vào Chủ nhật đầu tiên của tháng 11
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False3
Khi DST bắt đầu [dòng “bắt đầu”], đồng hồ treo tường địa phương nhảy từ 1. 59 đến 3. 00. Một bức tường thời gian của mẫu 2. MM không thực sự có ý nghĩa vào ngày đó, vì vậy
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
498 sẽ không mang lại kết quả với raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
499 vào ngày DST bắt đầu. For example, at the Spring forward transition of 2016, we get>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False4
When DST ends [the “end” line], there’s a potentially worse problem. there’s an hour that can’t be spelled unambiguously in local wall time. the last hour of daylight time. In Eastern, that’s times of the form 5. MM UTC on the day daylight time ends. The local wall clock leaps from 1. 59 [daylight time] back to 1. 00 [standard time] again. Local times of the form 1. MM are ambiguous.
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False72 mimics the local clock’s behavior by mapping two adjacent UTC hours into the same local hour then. In the Eastern example, UTC times of the form 5. MM and 6. MM both map to 1. MM when converted to Eastern, but earlier times have the
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'596 attribute set to 0 and the later times have it set to 1. For example, at the Fall back transition of 2016, we get
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False5
Note that the
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 instances that differ only by the value of the
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'596 attribute are considered equal in comparisons
Applications that can’t bear wall-time ambiguities should explicitly check the value of the
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'596 attribute or avoid using hybrid
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclasses; there are no ambiguities when using
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8, or any other fixed-offset
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclass [such as a class representing only EST [fixed offset -5 hours], or only EDT [fixed offset -4 hours]]
Xem thêm
IANA timezone database>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1The
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 module has a basic>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8 class [for handling arbitrary fixed offsets from UTC] and its7411 attribute [a UTC timezone instance]import pandas as pd import numpy as np import datetime
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1 brings the IANA timezone database [also known as the Olson database] to Python, and its usage is recommended
The Time Zone Database [often called tz, tzdata or zoneinfo] contains code and data that represent the history of local time for many representative locations around the globe. It is updated periodically to reflect changes made by political bodies to time zone boundaries, UTC offsets, and daylight-saving rules
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
8 Objects¶
The
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8 class is a subclass of
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4, each instance of which represents a timezone defined by a fixed offset from UTC
Objects of this class cannot be used to represent timezone information in the locations where different offsets are used in different days of the year or where historical changes have been made to civil time
class datetime. timezone[offset , name=None] ¶The offset argument must be specified as a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 object representing the difference between the local time and UTC. It must be strictly between
raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
426 and raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70],
'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']}
df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']]
df
427, otherwise >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'793 is raised
Đối số tên là tùy chọn. If specified it must be a string that will be used as the value returned by the
import pandas as pd
import numpy as np
import datetime
7420 methodMới trong phiên bản 3. 2
Changed in version 3. 7. The UTC offset is not restricted to a whole number of minutes.
Return the fixed value specified when the
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8 instance is constructed
The dt argument is ignored. The return value is a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'711 instance equal to the difference between the local time and UTC
Changed in version 3. 7. The UTC offset is not restricted to a whole number of minutes.
timezone. tzname[dt] ¶Return the fixed value specified when the
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8 instance is constructed
If name is not provided in the constructor, the name returned by
import pandas as pd
import numpy as np
import datetime
7424 is generated from the value of the import pandas as pd
import numpy as np
import datetime
7425 as follows. If offset is >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'783, the name is “UTC”, otherwise it is a string in the format
import pandas as pd
import numpy as np
import datetime
7427, where ± is the sign of import pandas as pd
import numpy as np
import datetime
7425, HH and MM are two digits of import pandas as pd
import numpy as np
import datetime
7429 and import pandas as pd
import numpy as np
import datetime
7430 respectivelyChanged in version 3. 6. Name generated from
import pandas as pd
import numpy as np
import datetime
7431 is now plain import pandas as pd
import numpy as np
import datetime
7432, not import pandas as pd
import numpy as np
import datetime
7433. timezone. dst[dt] ¶Always returns
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'703timezone. fromutc[dt] ¶
Return
import pandas as pd
import numpy as np
import datetime
7435. The dt argument must be an aware >>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 instance, with
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 set to
import pandas as pd
import numpy as np
import datetime
7438Thuộc tính lớp
timezone. utc ¶The UTC timezone,
import pandas as pd
import numpy as np
import datetime
7439import pandas as pd
import numpy as np
import datetime
7440 and import pandas as pd
import numpy as np
import datetime
7441 Behavior¶
import pandas as pd
import numpy as np
import datetime
import pandas as pd
import numpy as np
import datetime
import pandas as pd
import numpy as np
import datetime
62, >>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7, and
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 objects all support a
import pandas as pd
import numpy as np
import datetime
7445 method, to create a string representing the time under the control of an explicit format stringConversely, the
import pandas as pd
import numpy as np
import datetime
7446 class method creates a >>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 object from a string representing a date and time and a corresponding format string
The table below provides a high-level comparison of
import pandas as pd
import numpy as np
import datetime
7440 versus import pandas as pd
import numpy as np
import datetime
7441import pandas as pd
import numpy as np
import datetime
7450import pandas as pd
import numpy as np
import datetime
7451Usage
Convert object to a string according to a given format
Parse a string into a
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 object given a corresponding format
Type of method
Instance method
Class method
Method of
import pandas as pd
import numpy as np
import datetime
62; >>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7;
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7
Signature
import pandas as pd
import numpy as np
import datetime
7445import pandas as pd
import numpy as np
import datetime
7458import pandas as pd
import numpy as np
import datetime
7440 and import pandas as pd
import numpy as np
import datetime
7441 Format Codes¶
import pandas as pd
import numpy as np
import datetime
import pandas as pd
import numpy as np
import datetime
The following is a list of all the format codes that the 1989 C standard requires, and these work on all platforms with a standard C implementation
Directive
Meaning
Ví dụ
Notes
import pandas as pd
import numpy as np
import datetime
7461Ngày trong tuần là tên viết tắt của ngôn ngữ
CN, Mon, …, Sat [en_US];
So, Mo, …, Sa [de_DE]
[1]
import pandas as pd
import numpy as np
import datetime
7462Ngày trong tuần là tên đầy đủ của ngôn ngữ
Chủ Nhật, Thứ Hai, …, Thứ Bảy [en_US];
Sonntag, Montag, …, Samstag [de_DE]
[1]
import pandas as pd
import numpy as np
import datetime
7463Ngày trong tuần dưới dạng số thập phân, trong đó 0 là Chủ nhật và 6 là Thứ bảy
0, 1, …, 6
import pandas as pd
import numpy as np
import datetime
7464Ngày trong tháng dưới dạng số thập phân không đệm
01, 02, …, 31
[9]
import pandas as pd
import numpy as np
import datetime
7465Tháng là tên viết tắt của ngôn ngữ
Tháng 1, Tháng 2, …, Tháng 12 [en_US];
Tháng 1, Tháng 2, …, Dez [de_DE]
[1]
import pandas as pd
import numpy as np
import datetime
7466Tháng là tên đầy đủ của ngôn ngữ
Tháng Giêng, Tháng Hai, …, Tháng Mười Hai [en_US];
Januar, Februar, …, Tháng mười hai [de_DE]
[1]
import pandas as pd
import numpy as np
import datetime
7467Tháng dưới dạng số thập phân không đệm
01, 02, …, 12
[9]
import pandas as pd
import numpy as np
import datetime
7468Năm không có thế kỷ dưới dạng số thập phân không đệm
00, 01, …, 99
[9]
import pandas as pd
import numpy as np
import datetime
7469Năm với thế kỷ dưới dạng số thập phân
0001, 0002, …, 2013, 2014, …, 9998, 9999
[2]
import pandas as pd
import numpy as np
import datetime
7470Giờ [đồng hồ 24 giờ] dưới dạng số thập phân không đệm
00, 01, …, 23
[9]
import pandas as pd
import numpy as np
import datetime
7471Giờ [đồng hồ 12 giờ] dưới dạng số thập phân không đệm
01, 02, …, 12
[9]
import pandas as pd
import numpy as np
import datetime
7472Ngôn ngữ tương đương với AM hoặc PM
AM, PM [en_US];
sáng, chiều [de_DE]
[1], [3]
import pandas as pd
import numpy as np
import datetime
7473Phút dưới dạng số thập phân không đệm
00, 01, …, 59
[9]
import pandas as pd
import numpy as np
import datetime
7474Thứ hai dưới dạng số thập phân không đệm
00, 01, …, 59
[4], [9]
import pandas as pd
import numpy as np
import datetime
7475Micro giây dưới dạng số thập phân, được đệm bằng 0 thành 6 chữ số
000000, 000001, …, 999999
[5]
import pandas as pd
import numpy as np
import datetime
7476Độ lệch UTC ở dạng
import pandas as pd
import numpy as np
import datetime
7477 [chuỗi trống nếu đối tượng ngây thơ][trống], +0000, -0400, +1030, +063415, -030712. 345216
[6]
import pandas as pd
import numpy as np
import datetime
7478Tên múi giờ [chuỗi trống nếu đối tượng ngây thơ]
[trống], UTC, GMT
[6]
import pandas as pd
import numpy as np
import datetime
7479Ngày trong năm dưới dạng số thập phân không đệm
001, 002, …, 366
[9]
import pandas as pd
import numpy as np
import datetime
7480Số tuần của năm [Chủ nhật là ngày đầu tiên của tuần] dưới dạng số thập phân không đệm. Tất cả các ngày trong một năm mới trước Chủ nhật đầu tiên được coi là trong tuần 0
00, 01, …, 53
[7], [9]
import pandas as pd
import numpy as np
import datetime
7481Số tuần của năm [Thứ Hai là ngày đầu tiên của tuần] dưới dạng số thập phân không đệm. Tất cả các ngày trong một năm mới trước ngày thứ Hai đầu tiên được coi là trong tuần 0
00, 01, …, 53
[7], [9]
import pandas as pd
import numpy as np
import datetime
7482Đại diện ngày và giờ thích hợp của ngôn ngữ
Thứ ba 16 tháng 8 21. 30. 00 1988 [vi_Hoa Kỳ];
Di 16 Thg8 21. 30. 00 1988 [de_DE]
[1]
import pandas as pd
import numpy as np
import datetime
7483Đại diện ngày thích hợp của địa phương
16/08/88 [Không có];
16/08/1988 [en_US];
16. 08. 1988 [de_DE]
[1]
import pandas as pd
import numpy as np
import datetime
7484Đại diện thời gian thích hợp của địa phương
21. 30. 00 [vi_US];
21. 30. 00 [de_DE]
[1]
import pandas as pd
import numpy as np
import datetime
7485Một ký tự
import pandas as pd
import numpy as np
import datetime
7486 theo nghĩa đen%
Một số chỉ thị bổ sung không bắt buộc theo tiêu chuẩn C89 được bao gồm để thuận tiện. Tất cả các tham số này đều tương ứng với các giá trị ngày theo tiêu chuẩn ISO 8601
Directive
Meaning
Ví dụ
Notes
import pandas as pd
import numpy as np
import datetime
7487Năm ISO 8601 với thế kỷ đại diện cho năm chứa phần lớn tuần ISO [
import pandas as pd
import numpy as np
import datetime
7488]0001, 0002, …, 2013, 2014, …, 9998, 9999
[số 8]
import pandas as pd
import numpy as np
import datetime
7489ISO 8601 ngày trong tuần dưới dạng số thập phân trong đó 1 là Thứ Hai
1, 2, …, 7
import pandas as pd
import numpy as np
import datetime
7488ISO 8601 tuần dưới dạng số thập phân với Thứ Hai là ngày đầu tuần. Tuần 01 là tuần có ngày 04/01
01, 02, …, 53
[8], [9]
Những thứ này có thể không khả dụng trên tất cả các nền tảng khi được sử dụng với phương pháp
import pandas as pd
import numpy as np
import datetime
7440. Chỉ thị năm và tuần ISO 8601 không thể hoán đổi cho nhau với chỉ thị số năm và tuần ở trên. Gọi import pandas as pd
import numpy as np
import datetime
7441 với các chỉ thị ISO 8601 không đầy đủ hoặc mơ hồ sẽ làm tăng >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'793
Bộ mã định dạng đầy đủ được hỗ trợ khác nhau giữa các nền tảng, bởi vì Python gọi hàm
import pandas as pd
import numpy as np
import datetime
7440 của thư viện C của nền tảng và các biến thể nền tảng là phổ biến. Để xem toàn bộ mã định dạng được hỗ trợ trên nền tảng của bạn, hãy tham khảo tài liệu strftime[3]. Cũng có sự khác biệt giữa các nền tảng trong việc xử lý các thông số định dạng không được hỗ trợMới trong phiên bản 3. 6. ______17487,
import pandas as pd
import numpy as np
import datetime
7489 và import pandas as pd
import numpy as np
import datetime
7488 đã được thêm vào. Chi tiết kỹ thuật¶
Nói chung,
import pandas as pd
import numpy as np
import datetime
7498 hoạt động giống như >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'200 của mô-đun
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 mặc dù không phải tất cả các đối tượng đều hỗ trợ phương thức
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'542
Đối với phương thức của lớp
import pandas as pd
import numpy as np
import datetime
7446, giá trị mặc định là >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'203. bất kỳ thành phần nào không được chỉ định trong chuỗi định dạng sẽ được lấy từ giá trị mặc định. 4
Sử dụng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'204 tương đương với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'51
trừ khi định dạng bao gồm các thành phần giây phụ hoặc thông tin bù múi giờ, được hỗ trợ trong
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'205 nhưng bị loại bỏ bởi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'206
Đối với đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0, không nên sử dụng mã định dạng cho năm, tháng và ngày vì đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 không có giá trị như vậy. Nếu chúng vẫn được sử dụng, thì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'209 được thay thế cho năm và
import pandas as pd
import numpy as np
import datetime
65 cho tháng và ngàyĐối với đối tượng
import pandas as pd
import numpy as np
import datetime
62, không nên sử dụng mã định dạng cho giờ, phút, giây và micro giây vì đối tượng import pandas as pd
import numpy as np
import datetime
62 không có các giá trị như vậy. Nếu chúng vẫn được sử dụng, thì >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'714 sẽ được thay thế cho chúng
Vì lý do tương tự, việc xử lý các chuỗi định dạng chứa các điểm mã Unicode không thể được biểu thị trong bộ ký tự của ngôn ngữ hiện tại cũng phụ thuộc vào nền tảng. Trên một số nền tảng, các điểm mã như vậy được giữ nguyên trong đầu ra, trong khi trên các nền tảng khác,
import pandas as pd
import numpy as np
import datetime
7450 có thể tăng >>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'215 hoặc thay vào đó trả về một chuỗi trống
ghi chú
Vì định dạng phụ thuộc vào ngôn ngữ hiện tại nên cần cẩn thận khi đưa ra các giả định về giá trị đầu ra. Thứ tự trường sẽ khác nhau [ví dụ: “tháng/ngày/năm” so với “ngày/tháng/năm”] và đầu ra có thể chứa các ký tự Unicode được mã hóa bằng mã hóa mặc định của ngôn ngữ [ví dụ: nếu ngôn ngữ hiện tại là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
216,Phương pháp
7441 có thể phân tích các năm trong phạm vi [1, 9999] đầy đủ, nhưng các năm < 1000 phải được điền bằng 0 để có chiều rộng 4 chữ sốimport pandas as pd import numpy as np import datetime
Đã thay đổi trong phiên bản 3. 2. Trong các phiên bản trước, phương thức
7440 bị giới hạn trong các năm >= 1900.import pandas as pd import numpy as np import datetime
Đã thay đổi trong phiên bản 3. 3. Trong phiên bản 3. 2, phương pháp
7440 bị giới hạn trong các năm >= 1000.import pandas as pd import numpy as np import datetime
Khi được sử dụng với phương pháp
7441, lệnhimport pandas as pd import numpy as np import datetime
7472 chỉ ảnh hưởng đến trường giờ đầu ra nếu lệnhimport pandas as pd import numpy as np import datetime
7471 được sử dụng để phân tích cú pháp giờimport pandas as pd import numpy as np import datetime
Không giống như mô-đun
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0, mô-đun>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
7 không hỗ trợ giây nhuậnKhi được sử dụng với phương thức
7441, chỉ thịimport pandas as pd import numpy as np import datetime
7475 chấp nhận từ một đến sáu chữ số và số 0 ở bên phải.import pandas as pd import numpy as np import datetime
7475 là một phần mở rộng cho tập hợp các ký tự định dạng trong tiêu chuẩn C [nhưng được triển khai riêng trong các đối tượng ngày giờ và do đó luôn có sẵn]import pandas as pd import numpy as np import datetime
Đối với một đối tượng ngây thơ, mã định dạng
7476 vàimport pandas as pd import numpy as np import datetime
7478 được thay thế bằng các chuỗi rỗngimport pandas as pd import numpy as np import datetime
Đối với một đối tượng nhận thức
7476import pandas as pd import numpy as np import datetime
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
57 được chuyển đổi thành một chuỗi có dạng
7477, trong đóimport pandas as pd import numpy as np import datetime
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
67 là chuỗi 2 chữ số cho biết số giờ bù giờ UTC,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
238 là chuỗi 2 chữ số cho biết số phút bù giờ UTC,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
239 là chuỗi 2 chữ số cho biết . Phần>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
240 bị bỏ qua khi phần bù là một số nguyên giây và cả phần>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
240 và>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
239 đều bị bỏ qua khi phần bù là một số nguyên phút. Ví dụ: nếu>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
57 trả về>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
245, thì
7476 được thay thế bằng chuỗiimport pandas as pd import numpy as np import datetime
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
247Changed in version 3. 7. The UTC offset is not restricted to a whole number of minutes.
Đã thay đổi trong phiên bản 3. 7. Khi chỉ thị
7476 được cung cấp cho phương phápimport pandas as pd import numpy as np import datetime
7441, phần bù UTC có thể có dấu hai chấm làm dấu phân cách giữa giờ, phút và giây. Ví dụ:import pandas as pd import numpy as np import datetime
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
250 sẽ được phân tích thành phần bù của một giờ. Ngoài ra, cung cấp>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
251 giống với>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
252.
7478import pandas as pd import numpy as np import datetime
Trong
7440,import pandas as pd import numpy as np import datetime
7478 được thay thế bằng một chuỗi rỗng nếuimport pandas as pd import numpy as np import datetime
465 trả vềraw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70], 'birth_date': ['01-02-1996', '08-05-1997', '04-28-1996', '12-16-1995']} df = pd.DataFrame[raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']] df
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
703;
7441 chỉ chấp nhận các giá trị nhất định choimport pandas as pd import numpy as np import datetime
7478import pandas as pd import numpy as np import datetime
bất kỳ giá trị nào trong
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
261 cho ngôn ngữ máy của bạncác giá trị mã hóa cứng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
262 và>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
263
Vì vậy, ai đó sống ở Nhật Bản có thể có giá trị hợp lệ là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
264,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
262 và>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
263, nhưng có lẽ không phải là>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
267. Nó sẽ tăng>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
793 cho các giá trị không hợp lệĐã thay đổi trong phiên bản 3. 2. Khi chỉ thị
7476 được cung cấp cho phương thứcimport pandas as pd import numpy as np import datetime
7441, một đối tượngimport pandas as pd import numpy as np import datetime
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
7 nhận biết sẽ được tạo ra.>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 của kết quả sẽ được đặt thành phiên bản>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
8.Khi được sử dụng với phương pháp
7441,import pandas as pd import numpy as np import datetime
7480 vàimport pandas as pd import numpy as np import datetime
7481 chỉ được sử dụng trong các phép tính khi ngày trong tuần và năm dương lịch [import pandas as pd import numpy as np import datetime
7469] được chỉ địnhimport pandas as pd import numpy as np import datetime
Tương tự như
7480 vàimport pandas as pd import numpy as np import datetime
7481,import pandas as pd import numpy as np import datetime
7488 chỉ được sử dụng trong tính toán khi ngày trong tuần và năm ISO [import pandas as pd import numpy as np import datetime
7487] được chỉ định trong chuỗi định dạngimport pandas as pd import numpy as np import datetime
7441. Cũng lưu ý rằngimport pandas as pd import numpy as np import datetime
7487 vàimport pandas as pd import numpy as np import datetime
7469 không thể hoán đổi cho nhauimport pandas as pd import numpy as np import datetime
Khi được sử dụng với phương pháp
7441, số 0 đứng đầu là tùy chọn đối với các định dạngimport pandas as pd import numpy as np import datetime
7464,import pandas as pd import numpy as np import datetime
7467,import pandas as pd import numpy as np import datetime
7470,import pandas as pd import numpy as np import datetime
7471,import pandas as pd import numpy as np import datetime
7473,import pandas as pd import numpy as np import datetime
7474,import pandas as pd import numpy as np import datetime
7479,import pandas as pd import numpy as np import datetime
7480,import pandas as pd import numpy as np import datetime
7481 vàimport pandas as pd import numpy as np import datetime
7488. Định dạngimport pandas as pd import numpy as np import datetime
7468 không yêu cầu số 0 đứng đầuimport pandas as pd import numpy as np import datetime
chú thích
1Nghĩa là, nếu chúng ta bỏ qua các tác động của Thuyết tương đối
2Điều này phù hợp với định nghĩa của lịch “proleptic Gregorian” trong cuốn sách Tính toán Lịch của Dershowitz và Reingold, trong đó nó là lịch cơ sở cho tất cả các phép tính. Xem sách để biết các thuật toán chuyển đổi giữa các thứ tự Gregorian proleptic và nhiều hệ thống lịch khác