1

Here is my dataset:

dataset

And want to convert my dataset between two dates. I have tried the solution mentioned here. But it didn't work.

Here is a screenshot using:

Boolean MaskBoolean Mask

and DatetimeIndex DatetimeIndex

Saurav
  • 75
  • 8
  • Looks like your data after filter doesn't have 100 rows, while `pd.date_range(..., periods=100, freq='D')` does. – Quang Hoang Jun 05 '20 at 18:27
  • I edited the screenshot, please see again! – Saurav Jun 05 '20 at 18:33
  • 1
    what do you mean by "it didn't work"? the boolean mask screen shot seems to show only rows with dates in between the specified start and end date (aka it looks like it worked) – Tom Jun 05 '20 at 18:50
  • It should have shown data from 2020-03-25 rather than 2020-04-02 – Saurav Jun 05 '20 at 18:53
  • 1
    Please post your code as text instead of images. It would help if you copy and pasted the error messages too. See [how to make reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – kennyvh Jun 06 '20 at 08:14

1 Answers1

1

I tried to recreate the scenario shared by you with the same data. While exploring the results, I observed that the data is not in sorted format.

Try to run sort_values('Date') on your result.

data[(data['Date'] >= '2020-03-25') & (data['Date'] <= '2020-05-22')].sort_values('Date')

enter image description here

You will get above result.

Vinit Neogi
  • 376
  • 5
  • 10