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!

Fabio Lamanna
  • 20,504
  • 24
  • 90
  • 122

2 Answers2

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

Community
  • 1
  • 1
Ashish Kumar
  • 347
  • 4
  • 12
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]
Parfait
  • 104,375
  • 17
  • 94
  • 125