How To Fix This “typeerror: Sequence Item 0: Expected Str Instance, Float Found”
I am trying to combine the cell values (strings) in a dataframe column using groupby method, separating the cell values in the grouped cell using commas. I ran into the following e
Solution 1:
As mentioned in the comments, the NaN
is a float, so trying to do string operations on it doesn't work (and this is the reason for the error message)
Replace your last part of code with this: The filling of the nan is done with boolean indexing according to the logic you specified in your comment
# If a cell has a borough but a Not assigned neighborhood, then the neighborhood will be the same as the borough
toronto_df.Neighbourhood = np.where(toronto_df.Neighbourhood.isnull(),toronto_df.Borough,toronto_df.Neighbourhood)
toronto_df['Neighbourhood'] = toronto_df.groupby(['Postcode','Borough'])['Neighbourhood'].agg(lambda x: ','.join(x))
Post a Comment for "How To Fix This “typeerror: Sequence Item 0: Expected Str Instance, Float Found”"