Change language

Python | pandas.date_range () method

|

pandas.date_range() is one of the core functions in Pandas that is used to return a fixed DatetimeIndex frequency.

Syntax: pandas.date_range (start = None, end = None, periods = None, freq = None, tz = None, normalize = False, name = None, closed = None, ** kwargs)

Parameters:
start: Left bound for generating dates.
end: Right bound for generating dates .
periods: Number of periods to generate.
freq: Frequency strings can have multiples, eg ’5H’. See here for a list of frequency aliases.
tz: Time zone name for returning localized DatetimeIndex. By default, the resulting DatetimeIndex is timezone-naive.
normalize: Normalize start / end dates to midnight before generating date range.
name: Name of the resulting DatetimeIndex.
closed: Make the interval closed with respect to the given frequency to the ’left’, ’right’, or both sides (None, the default).

Returns: DatetimeIndex

Code # 1:

# import pandas as pd

import pandas as pd

 

per1 = pd.date_range (start = ’1-1-2018’

  end = ’ 1-05-2018’ , freq = ’5H’ )

  

for val in per1:

  print (val)

Output:

Code # 2:

# import pandas as pd

import pandas as pd

  

dRan1 = pd. date_range (start = ’1-1-2018’ ,

end = ’8-01-2018’ , freq = ’ M’ )

 

dRan2 = pd.date_range (start = ’1-1-2018’

  end = ’ 11-01-2018’ , freq = ’3M’  )

 

print (dRan1, ’ ’ , dRan2)

Output:

Code # 3:

# import pandas as pd

import pandas as pd

 
# Specify the beginning and periods, the number of periods (days).

dRan1 = pd.date_range (start = ’1-1-2018’ , p eriods = 13 )

 
# Specify the end and periods, the number of periods (days).

dRan2 = pd.date_range (end = ’1-1-2018’ , periods = 13 )

 
# Specify start, end and periods; Frequency
# generated automatically (with linear spacing).

dRan3 = pd.date_range (start = ’01-03-2017’

  end = ’ 1-1-2018’ , periods = 13 )

 

print (dRan1, "" , dRan2, ’’ , dRan3)

Output:

Code # 4:

# import pandas as pd

import pandas as pd

 
# Specify the start and periods, the number of periods (days).

dRan1 = pd.date_range (start = ’1-1-2018’

  periods = 13 , tz = ’Asia / Tokyo’ )

 
dRan1

Output:

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method