how do i remove words from rows in a dataset?

I would use:

only_counties = usa_only[usa_only['AdminRegion2'].str.contains("", na = False)].copy() # now only_counties is a sliced copy of usa_only, not a view

only_counties['AdminRegion2'] = only_counties['AdminRegion2'].str.replace(' County', '')
only_counties['AdminRegion2'] = only_counties['AdminRegion2'].str.replace(' Census Area', '')
only_counties['AdminRegion2'] = only_counties['AdminRegion2'].str.replace(' Borough', '')

That should do the trick

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top