0

When I use df.apply(pd.Series.str.upper) shows me an error -

Although df.apply(pd.Series.min) is running absolutely fine! and df.apply(lambda x: x.str.upper()) is running fine too.

df = pd.DataFrame(
    {
     "Name":[
         "Harry","Sam", "Jack"], "Gender": ["M","M","F"]})


df.apply(pd.Series.str.lower)
Error - Series' object has no attribute '_inferred_dtype'

2 Answers2

2

When you apply pd.Series.str its converting each row to String Series type hence lower method would not work unless you apply individually like below

df = pd.DataFrame(
    {
     "Name":[
         "Harry","Sam", "Jack"], "Gender": ["M","M","F"]
    }
)
df.apply(pd.Series.str) # Check output in below image

Appliying_Series_Str

Its clear if you want to apply lower you have to iteratively apply at every instance hence 'lambda' would be useful

df.apply(lambda x: x.str.lower())
Abhi
  • 1,080
  • 1
  • 7
  • 21
1

Simply adapt your upper() approach, it should give you the expected result:

df.apply(lambda x: x.str.lower())
HedgeHog
  • 22,146
  • 4
  • 14
  • 36