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

5
  • Looks like your data after filter doesn't have 100 rows, while pd.date_range(..., periods=100, freq='D') does. Commented Jun 5, 2020 at 18:27
  • I edited the screenshot, please see again! Commented Jun 5, 2020 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) Commented Jun 5, 2020 at 18:50
  • It should have shown data from 2020-03-25 rather than 2020-04-02 Commented Jun 5, 2020 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. Commented Jun 6, 2020 at 8:14

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.