I'm trying to change the values in a single column using pandas apply(). My function partially worked, but I'm stuck on how to fix this other half.
Data Column:
County Name
Riverside County
San Diego County
SanFrancisco County/city
I'm trying to get rid of " County" so I'm left with just the name of the county. I successfully got rid of the " County" with the function but I'm having trouble removing the " County/city" from San Francisco.
Code:
def modify_county(countyname):
if "/city" in countyname:
return countyname.replace(" County/city","")
return countyname.replace(" County","")
lfd["CountyName"] = lfd["CountyName"].apply(modify_county)
Output:
CountyName
Riverside
San Diego
San Francisco County/city
Is something wrong with the conditional in the function?