I have a dataframe index of dates, ranging from 2001 to 2015. I want to isolate the 2015 dates. I want to take advantage of the format -- all dates starting with the full year - e.g. 2004abc...
I would like to simply create a new dataframe, of all elements where the date starts with 2015.
When the column is a string, I am able to do it like this:
df1 = df[df['some column name']=='some string']
But when I try
df[df['some column name']str.startwith('2015')]
I get an error.
Is there anyway to do this?
The error I get is just not recognizing the 'some column name' in df['some column name'].
Edit: Just a short edit to say that I think the problem here was due to trying to filter on the index, which might be handled differently that a regular column. See @Jezrael's answer below which worked.