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
  • 57,915
  • 7
  • 66
  • 89
amiref
  • 3,181
  • 7
  • 38
  • 62

1 Answers1

6

You need two function call from str

df["col2"].str.strip().str.lower()
BENY
  • 317,841
  • 20
  • 164
  • 234