I'm just getting up to speed on Pandas and cannot resolve one issue. I have a list of Counties in NY State. If the County is one of the 5 boroughs, I want to change the county name to New York, otherwise I leave it alone. The following gives the idea, but is not correct.
EDIT - so if the counties in the County column of the first few rows were Albany, Allegheny, Bronx before the change, they would be Albany, Allegheny, New York after the change
# clean up county names
# 5 boroughs must be combined to New York City
# eliminate the word county
nyCounties = ["Kings", "Queens", "Bronx", "Richmond", "New York"]
nypopdf['County'] = ['New York' for nypopdf['County'] in nyCounties else
nypopdf['County']]
#nypopdf['County'] = ['New York' for nypopdf['County'] in nyCounties else. you Probably meant to have#nypopdf['County'] = ['New York' for nypopdf['County'] in nyCounties else nypopdf['County']]