Search code examples
pythondatetimedata-analysisseries

How to create a timeseries starting "2000-01-01" and 10 weekends(saturdays) after that having random numbers as values.(in Python)?


rnge = pd.date_range(start = "2000-01-01" ,periods =14 , freq = "D")
rnge

I want saturdays to be excluded.


Solution

  • I'm not sure whether I understood the question (didn't get the part about random numbers). If you just want to filter out Saturdays then it can be done like this:

    rnge = pd.date_range(start="2000-01-01", periods=14, freq="D")
    rnge = rnge[rnge.weekday != 5]
    

    Result:

    DatetimeIndex(['2000-01-02', '2000-01-03', '2000-01-04', '2000-01-05',
                   '2000-01-06', '2000-01-07', '2000-01-09', '2000-01-10',
                   '2000-01-11', '2000-01-12', '2000-01-13', '2000-01-14'],
                  dtype='datetime64[ns]', freq=None)