Python | Панды tseries.offsets.DateOffset.copy
Смещения даты - это стандартный вид приращения даты, используемый для диапазона дат в Pandas. Он работает точно так же, как relativedelta с точки зрения аргументов ключевого слова, которые мы передаем. DateOffets работает следующим образом, каждое смещение определяет набор дат, соответствующих DateOffset. Например, Bday определяет этот набор как набор дат, являющихся рабочими днями (MF).
DateOffsets могут быть созданы для перемещения дат вперед на заданное количество допустимых дат. Например, Bday (2) можно добавить к дате, чтобы переместить ее на два рабочих дня вперед. Если дата не начинается с действительной даты, сначала она перемещается на действительную дату, а затем создается смещение.
Pandas tseries.offsets.DateOffset.copy() function returns a copy of the given DateOffset object.
Syntax: pandas.tseries.offsets.DateOffset.copy()
Parameter : None
Returns : copy of the given object
Example #1: Use pandas.tseries.offsets.DateOffset.copy() function to return a copy of the given DateOffset object.
# importing pandas as pdimport pandas as pd # importing the to_offset functionfrom pandas.tseries.frequencies import to_offset # Creating Timestampts = pd.Timestamp("2019-10-10 07:15:11") # Create the DateOffset of 2 daydo = to_offset(freq = "2D") # Print the Timestampprint(ts) # Print the DateOffsetprint(do) |
Выход :


Now we will add the dateoffset to the given timestamp object to increment the datetime value. We will also return a copy of the given DateOffset object.
# Adding the dateoffset to the given timestampnew_timestamp = ts + do # Print the updated timestampprint(new_timestamp) # Now we will create a copy of the given# DateOffset object.do_copy = do.copy() # Check if the two objects are same or notprint(do_copy is do) |
Выход :


As we can see in the output, the function has successfully created a copy of the given Dateoffset object. False indicates the two objects are not same.
Example #2: Use pandas.tseries.offsets.DateOffset.copy() function to return a copy of the given DateOffset object.
# importing pandas as pdimport pandas as pd # importing the to_offset functionfrom pandas.tseries.frequencies import to_offset # Creating Timestampts = pd.Timestamp("2019-10-10 07:15:11") # Create the DateOffsetdo = to_offset(freq = "10D2H") # Print the Timestampprint(ts) # Print the DateOffsetprint(do) |
Выход :


Now we will add the dateoffset to the given timestamp object to increment the datetime value. We will also return a copy of the given DateOffset object.
# Adding the dateoffset to the given timestampnew_timestamp = ts + do # Print the updated timestampprint(new_timestamp) # Now we will create a copy of the given# DateOffset object.do_copy = do.copy() # Check if the two objects are same or notprint(do_copy is do) |
Выход :


As we can see in the output, the function has successfully created a copy of the given Dateoffset object. False indicates the two objects are not same.
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.