0

I have a pandas dataframe called Data filled with dates. An example date might look like: "2015-05-10 23:45:00". I want to look at the data in January only, so I want:

Data= Data[:][5:7]=="01"

This doesn't work though.

TDLR, wondering how to find get subset of a dataframe based on a substring.

Thanks!

2 Answers 2

0

Consider using the bracketed filter with datetime's month value. But first, you will need to convert string dates to datetime which can be handled with panda's to_datetime():

import datetime as dt
...

Data['yourdatetimecolumn'] = pd.to_datetime(Data['yourdatetimecolumn'])
JanData = Data[Data['yourdatetimecolumn'].dt.month==1]
Sign up to request clarification or add additional context in comments.

Comments

0

since your query is with regards to Dates, want to start first by looking this up? and give it a try may be.. Parse a Pandas column to Datetime

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.