I have a dataframe with the original column 'All' , which I split into RegionName1 and RegioName2 columns. There are duplicate entries, for example, Duluth and Duluth (University of Minnesota Duluth. I want to convert strings like Duluth (University of Minnesota Duluth to NaN values. So I have tried
unitown['RegionName2'] = [np.nan if '(' in x else x for x in unitown['RegionName2']]
and got an error that TypeError: argument of type 'float' is not iterable. What else can I try?
unitown=pd.read_table('university_towns.txt', header=None).rename(columns={0:'All'})
unitown['State']=unitown['All'].apply(lambda x: x.split('[edi')[0].strip() if x.count('[edi') else np.NaN).fillna(method="ffill") #.fillna(method="ffill")
unitown['RegionName1'] = unitown['All'].apply(lambda x: x.split('(')[0].strip() if x.count('(') else np.NaN)
unitown['RegionName2'] = unitown['All'].apply(lambda x: x.split(',')[0].strip() if x.count(',') else np.NaN)
unitown['RegionName2'] = [np.nan if '(' in x else x for x in unitown['RegionName2']]
return unitown[unitown.State=='Minnesota']
