Reputation: 111
I'm trying to create a subset of my 'monthstest' dataframe that only includes results from the year 2018.
When I try the following I get an error,
I have tried changing the data type from an object to a string using the following but it stays as an object.
Any ideas what I should do?
Upvotes: 0
Views: 76
Reputation: 61
From your line:
monthstest[monthstest.str.contains('-18')]
# the monthstest inside [] is the entire dataframe, which contains fields other than 'Months', so comparing '-18' against one row of record is not well-defined.
So, you may try to consider the 'Month' column only:
monthstest[monthstest['Month'.str.contains('18-')]] # i think it is '18-'?
another way to do it (don't know if its more efficient though):
monthstest[ ['18-' in m for m in monthstest['Month']] ]
Upvotes: 0
Reputation: 2098
What you probably want to do is:
monthstest[monthstest["Months"].str.contains("18-")]
Upvotes: 1