Thursday, June 11, 2020

How to generate the dates range from one to other

In general, pandas is good for time series and generate the date ranges:

Example 1:

import pandas as pd
dates1 = pd.date_range('11/06/2020', periods=7)
timeseries = pd.Series(np.arange(7), index=dates)
timeseries .to_csv(r'G:\DatascienceProjects\examples_datasets\tseries.csv')

Example 2:
import pandas as pd
date1 = '2020-05-03'
date2 = '2020-05-11'
mydates = pd.date_range(date1, date2).tolist()
Similarly, we can use bdate_range if you need only weekdays during the analysis.
Website for reference:

No comments:

Post a Comment

Element wise operation on LIST vs ARRAY

The use of arrays over lists: You can write  vectorised  code on numpy arrays, not on lists, which is  convenient to read and write, and con...