1

I'm trying to generate a pandas timeseries where all values are 1.

start=str(timeseries.index[0].round('S'))
end=str(timeseries.index[-1].round('S'))

empty_series_index = pd.date_range(start=start, end=end, freq='2m')
empty_series_values = 1
empty_series = pd.Series(data=empty_series_values, index=empty_series_index)

print(start,end)
print(empty_series)

The printout reads

2019-09-20 00:30:51+00:00 2019-10-30 23:57:35+00:00

2019-09-30 00:30:51+00:00    1

Why is there only one value, even tough its a 2min frequency and its more than 10 days long?

cheesus
  • 733
  • 1
  • 4
  • 24
  • 1
    `freq='2min'` (or `'2T'`) not `'2m'`, which is interpreted as 2 months. – ALollz Nov 05 '19 at 17:59
  • that's it and can be marked as answer – cheesus Nov 05 '19 at 18:00
  • I don't know that I could really add anything more than is already stated in: https://stackoverflow.com/questions/35339139/where-is-the-documentation-on-pandas-freq-tags. These are often mixed up because `pd.to_datetime` uses '%M' for the Minute formatting and '`%m'` for month. – ALollz Nov 05 '19 at 18:07

1 Answers1

0

in the line: empty_series_index = pd.date_range(start=start, end=end, freq='2m') you are using the frequency string: '2m' which actually means 2 months.

If you want to use minutes you should use: '2min' or '2T' (from documentation)

Hope this helps. Let me know if you have any more questions.

Elegant Code
  • 508
  • 2
  • 14