Python | Панды tseries.offsets.CustomBusinessDay.isAnchored
Смещения даты - это стандартный вид приращения даты, используемый для диапазона дат в Pandas. Он работает точно так же, как relativedelta с точки зрения аргументов ключевого слова, которые мы передаем. DateOffets работает следующим образом, каждое смещение определяет набор дат, соответствующих DateOffset. Например, Bday определяет этот набор как набор дат, являющихся рабочими днями (MF).
DateOffsets могут быть созданы для перемещения дат вперед на заданное количество допустимых дат. Например, Bday (2) можно добавить к дате, чтобы переместить ее на два рабочих дня вперед. Если дата не начинается с действительной даты, сначала она перемещается на действительную дату, а затем создается смещение.
Pandas tseries.offsets.CustomBusinessDay.isAnchored() function to check if the given offset object is anchored or not.
Syntax: pandas.tseries.offsets.CustomBusinessDay.isAnchored()
Parameter : None
Returns : boolean
Example #1: Use pandas.tseries.offsets.CustomBusinessDay.isAnchored() function to check if the given offset object is anchored or not.
# importing pandas as pdimport pandas as pd # Creating Timestampts = pd.Timestamp("2019-4-23 11:15:00") # Create an offsetcbd = pd.tseries.offsets.CustomBusinessDay(weekmask = "Mon Tue Wed") # Print the Timestampprint(ts) # Print the Offsetprint(cbd) |
Выход :


Now we will add the offset to the given timestamp object to increment the datetime value. We will also check if the given offset object is anchored or not.
# Adding the offset to the given timestampnew_timestamp = ts + cbd # Print the updated timestampprint(new_timestamp) # check if the offset object# is anchored or notresult = cbd.isAnchored() # print the resultprint(result) |
Выход :


Как видно из выходных данных, мы успешно создали смещение и добавили его к заданной временной метке. Мы также проверили, привязан ли данный объект смещения или нет.
Example #2: Use pandas.tseries.offsets.CustomBusinessDay.isAnchored() function to check if the given offset object is anchored or not.
# importing pandas as pdimport pandas as pd # Creating Timestampts = pd.Timestamp("2019-4-23 11:15:00") # Create an offsetcbd = pd.tseries.offsets.CustomBusinessDay(n = 3, weekmask = "Mon Tue Wed Thu") # Print the Timestampprint(ts) # Print the Offsetprint(cbd) |
Выход :


Now we will add the offset to the given timestamp object to increment the datetime value. We will also check if the given offset object is anchored or not.
# Adding the offset to the given timestampnew_timestamp = ts + cbd # Print the updated timestampprint(new_timestamp) # check if the offset object# is anchored or notresult = cbd.isAnchored() # print the resultprint(result) |
Выход :


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