Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Python Pandas - 범위의 날짜 생성

<시간/>

범위에서 날짜를 생성하려면 date _range() 메서드를 사용합니다. 먼저 별칭을 사용하여 필요한 pandas 라이브러리를 가져옵니다. -

import pandas as pd

이제 정렬에서 날짜를 생성해야 하므로 이를 위해 시작하려는 날짜를 언급합니다. 여기에서 우리는 2021년 6월 1일과 60일의 기간을 언급했습니다 -

dates = pd.date_range('6/1/2021', periods=60)

예시

다음은 전체 코드입니다 -

import pandas as pd

# generate dates in a range
# period is 60 i.e. 60 days from 1st June 2021
dates = pd.date_range('6/1/2021', periods=60)

print"Displaying dates in a range...\n",dates

출력

이것은 다음과 같은 출력을 생성합니다 -

Displaying dates in a range...
   DatetimeIndex(['2021-06-01', '2021-06-02', '2021-06-03', '2021-06-04',
                  '2021-06-05', '2021-06-06', '2021-06-07', '2021-06-08',
                  '2021-06-09', '2021-06-10', '2021-06-11', '2021-06-12',
                  '2021-06-13', '2021-06-14', '2021-06-15', '2021-06-16',
                  '2021-06-17', '2021-06-18', '2021-06-19', '2021-06-20',
                  '2021-06-21', '2021-06-22', '2021-06-23', '2021-06-24',
                  '2021-06-25', '2021-06-26', '2021-06-27', '2021-06-28',
                  '2021-06-29', '2021-06-30', '2021-07-01', '2021-07-02',
                  '2021-07-03', '2021-07-04', '2021-07-05', '2021-07-06',
                  '2021-07-07', '2021-07-08', '2021-07-09', '2021-07-10',
                  '2021-07-11', '2021-07-12', '2021-07-13', '2021-07-14',
                  '2021-07-15', '2021-07-16', '2021-07-17', '2021-07-18',
                  '2021-07-19', '2021-07-20', '2021-07-21', '2021-07-22',
                  '2021-07-23', '2021-07-24', '2021-07-25', '2021-07-26',
                  '2021-07-27', '2021-07-28', '2021-07-29', '2021-07-30'],
                 dtype='datetime64[ns]', freq='D')