Python | Панды tseries.offsets.BusinessDay.name
Смещения даты - это стандартный вид приращения даты, используемый для диапазона дат в Pandas. Он работает точно так же, как relativedelta с точки зрения аргументов ключевого слова, которые мы передаем. DateOffets работает следующим образом, каждое смещение определяет набор дат, соответствующих DateOffset. Например, Bday определяет этот набор как набор дат, являющихся рабочими днями (MF).
DateOffsets могут быть созданы для перемещения дат вперед на заданное количество допустимых дат. Например, Bday (2) можно добавить к дате, чтобы переместить ее на два рабочих дня вперед. Если дата не начинается с действительной даты, сначала она перемещается на действительную дату, а затем создается смещение.
Pandas tseries.offsets.BusinessDay.name attribute allows you to use the offset in functions for simplicity instead of importing and initializing the class. It also returns the name of the frequency that is applied to the offset object.
Syntax: pandas.tseries.offsets.BusinessDay.name
Parameter : None
Returns : name
Example #1: Use pandas.tseries.offsets.BusinessDay.name attribute to return the name of the frequency applied on the given offset object.
# importing pandas as pdimport pandas as pd # Creating Timestampts = pd.Timestamp("2019-10-10 07:15:11") # Create an offset of 5 Business daysbd = pd.tseries.offsets.BusinessDay(n = 5) # Print the Timestampprint(ts) # Print the DateOffsetprint(bd) |
Выход :


Now we will add the Business day offset to the given timestamp object to increment the datetime value. We will also print the name of the frequency applied on the given offset object.
# Adding the Business day offset to the given timestampnew_timestamp = ts + bd # Print the updated timestampprint(new_timestamp) # Print the name of the frequency applied # on the given offset objectprint(bd.name) |
Выход :


Как видно из выходных данных, мы успешно создали смещение в 5 рабочих дней и добавили его к заданной временной метке. Мы также напечатали имя частоты, применяемой к данному объекту смещения.
Example #2 : Use pandas.tseries.offsets.BusinessDay.name attribute to return the name of the frequency applied on the given offset object.
# importing pandas as pdimport pandas as pd # Creating Timestampts = pd.Timestamp("2019-10-10 07:15:11") # Create an offset of 10 Business days and 10 hoursbd = pd.tseries.offsets.BusinessDay(offset = datetime.timedelta(days = 10, hours = 10)) # Print the Timestampprint(ts) # Print the DateOffsetprint(bd) |
Выход :


Now we will add the Business day offset to the given timestamp object to increment the datetime value. We will also print the name of the frequency applied on the given offset object.
# Adding the Business day offset to the given timestampnew_timestamp = ts + bd # Print the updated timestampprint(new_timestamp) # Print the name of the frequency applied # on the given offset objectprint(bd.name) |
Выход :


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