Python | pandas.period_range () метод
Python - отличный язык для анализа данных, в первую очередь из-за фантастической экосистемы пакетов Python, ориентированных на данные. Pandas - один из таких пакетов, который значительно упрощает импорт и анализ данных.
pandas.period_range() is one of the general functions in Pandas which is used to return a fixed frequency PeriodIndex, with day (calendar) as the default frequency.
Syntax: pandas.to_numeric(arg, errors=’raise’, downcast=None)
Parameters:
start : Left bound for generating periods
end : Right bound for generating periods
periods : Number of periods to generate
freq : Frequency alias
name : Name of the resulting PeriodIndexReturns: PeriodIndex
Code #1:
# importing pandas as pdimport pandas as pd # period_range with freq = dayper1 = pd.period_range(start ="2018-12-20", end ="2019-01-01", freq ="D") # period_range with freq = monthper2 = pd.period_range(start ="2018-12-20", end ="2019-12-01", freq ="M") print(per1, "
", per2) |
Выход:
Code #2:
# importing pandas as pdimport pandas as pd # period_range with freq = dayper1 = pd.period_range(start ="2018-12-20", end ="2019-01-01", freq ="D") for val in per1: print(val) |
Output:
Code #3:
# importing pandas as pdimport pandas as pd # Calling with pd.Periodper = pd.period_range(start = pd.Period("2017Q1", freq ="Q"), end = pd.Period("2018Q2", freq ="Q"), freq ="M") for val in per: print(val) |
Выход:
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.