Python | Панды tseries.offsets.CustomBusinessHour.copy

Опубликовано: 27 Марта, 2022

Смещения даты - это стандартный вид приращения даты, используемый для диапазона дат в Pandas. Он работает точно так же, как relativedelta с точки зрения аргументов ключевого слова, которые мы передаем. DateOffets работает следующим образом, каждое смещение определяет набор дат, соответствующих DateOffset. Например, Bday определяет этот набор как набор дат, являющихся рабочими днями (MF).

DateOffsets могут быть созданы для перемещения дат вперед на заданное количество допустимых дат. Например, Bday (2) можно добавить к дате, чтобы переместить ее на два рабочих дня вперед. Если дата не начинается с действительной даты, сначала она перемещается на действительную дату, а затем создается смещение.

Pandas tseries.offsets.CustomBusinessHour.copy() function is used to create a copy of the given offset object.

Syntax: pandas.tseries.offsets.CustomBusinessHour.copy()

Parameter : None

Returns : create a copy of the offset object

Example #1: Use pandas.tseries.offsets.CustomBusinessHour.copy() function to create a copy of the given offset object.

# importing pandas as pd
import pandas as pd
  
# Creating Timestamp
ts = pd.Timestamp("2019-4-23 11:15:00")
  
# Create an offset
cbh = pd.tseries.offsets.CustomBusinessHour(n = 2, weekmask = "Mon Tue Wed Thu",
                                           start ="12:00")
  
# Print the Timestamp
print(ts)
  
# Print the Offset
print(cbh)

Выход :

Now we will add the offset to the given timestamp object to increment the datetime value. We will also create a copy of the given offset object.

# Adding the offset to the given timestamp
new_timestamp = ts + cbh
  
# Print the updated timestamp
print(new_timestamp)
  
# create a copy
cbh_copy = cbh.copy()
  
# check if the two objects are same
print(cbh_copy is cbh)

Выход :

Как видно из выходных данных, мы успешно создали смещение и добавили его к заданной временной метке. Мы также проверили, совпадают ли два объекта.

Example #2: Use pandas.tseries.offsets.CustomBusinessHour.copy() function to create a copy of the given offset object.

# importing pandas as pd
import pandas as pd
  
# Creating Timestamp
ts = pd.Timestamp("2019-4-23 11:15:00")
  
# Create an offset
cbh = pd.tseries.offsets.CustomBusinessHour(start ="07:00", end ="14:00")
  
# Print the Timestamp
print(ts)
  
# Print the Offset
print(cbh)

Выход :

Now we will add the offset to the given timestamp object to increment the datetime value. We will also create a copy of the given offset object.

# Adding the offset to the given timestamp
new_timestamp = ts + cbh
  
# Print the updated timestamp
print(new_timestamp)
  
# create a copy
cbh_copy = cbh.copy()
  
# check if the two objects are same
print(cbh_copy is cbh)

Выход :

Как видно из выходных данных, мы успешно создали смещение и добавили его к заданной временной метке. Мы также проверили, совпадают ли два объекта.

Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.

Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.