pandas - Subset of Dataframe based on substring (python) -


i have pandas dataframe called data filled dates. example date might like: "2015-05-10 23:45:00". want @ data in january only, want:

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

this doesn't work though.

tdlr, wondering how find subset of dataframe based on substring.

thanks!

consider using bracketed filter datetime's month value. first, need convert string dates datetime can handled panda's to_datetime():

import datetime dt ...  data['yourdatetimecolumn'] = pd.to_datetime(data['yourdatetimecolumn']) jandata = data[data['yourdatetimecolumn'].dt.month==1] 

Comments