1

I have the following dataframe and I'd like to remove all the whitespace characters and make it lowercase:

df = pd.DataFrame({"col1":[1,2,3,4], "col2":["A","B ", "Cc","D"]})

I tried to do that via df[["col2"]].apply(lambda x: x.strip().lower()) but it raises an error:

AttributeError: ("'Series' object has no attribute 'strip'", 'occurred at index col2')
ALollz
  • 54,844
  • 7
  • 56
  • 77
amiref
  • 2,881
  • 6
  • 32
  • 52

1 Answers1

4

You need two function call from str

df["col2"].str.strip().str.lower()
BENY
  • 296,997
  • 19
  • 147
  • 204