Reputation: 1056
I have a column in a dataframe called 'Year'. When I invoke;
filtered_df['Year'].unique()
My result is:
array([2013, 2012, 2014, 2015, 2016, 2017, 2011, 2010, 2009, 2008, '2011', '2010', '2015', '2009', 'N 117 ST / GREENWOOD AV N'], dtype=object)
I would like to combine the results of the '2011','2010', '2015', and '2009'
instances with that of their non-string counterparts. I thought it might be possible to do so using a regular expression, but the only things I have attempted thus far have returned errors that make me believe that my methodology is inherently flawed, so I have not included them here.
Any ideas for a computationally efficient solution to this problem?
Upvotes: 0
Views: 2137
Reputation: 210832
usually we convert it to numeric values (all non-convertable values will be converted into NaN
's) in the following way:
filtered_df['Year'] = pd.to_numeric(filtered_df['Year'], errors='coerce')
Upvotes: 2