Home > Enterprise >  Replacing values in pandas dataframe using values in a list
Replacing values in pandas dataframe using values in a list

Time:05-26

I have a column in my df which ends with ['-A','-B','-T','-Z','-EQ','-BE','-BL','-BT','-GC','-IL','-IQ'], and I need to remove the values.

I tried the below and got an error

df['name'] = df['name'].str.replace(['-A','-B','-T','-Z','-EQ','-BE','-BL','-BT','-GC','-IL','-IQ'],'', regex=True)

TypeError: unhashable type: 'list'

CodePudding user response:

Use Series.replace instead Series.str.replace:

df['name'] = df['name'].replace(['-A','-B','-T','-Z','-EQ','-BE','-BL','-BT','-GC','-IL','-IQ'],'', regex=True)
  • Related