I have this pandas dataframe:
JavaScript
x
13
13
1
custid age income gen wp mp lip
2
CustAtt
3
0 101 45 $45K Male No Yes No
4
1 106 40 $39K Female Yes Yes Yes
5
2 111 42 $46K Male No No No
6
3 116 43 $36K Male Yes Yes Yes
7
4 121 38 $59K Female No Yes Yes
8
5 126 55 $28K Female No No No
9
6 131 35 $35K Male No Yes Yes
10
7 136 27 $26K Male Yes No No
11
8 141 43 $36K Male No Yes No
12
9 146 41 $38K Female Yes Yes No
13
And what I want to do is use apply() with a function to convert all the data to lowercase. I couldn’t find anything on the internet showing how to do this, I am currently stuck with this.
JavaScript
1
4
1
def low(x):
2
return x.lower()
3
df.apply(low)
4
however it gives me error that series object has no attribute lower. Any help greatly appreciated! Thanks!
Advertisement
Answer
That’s because column custid and age have a integer values. Integer value doesn’t have lower() function.
For example, if you want to change gen’s data to a lower case, you can implement it like below.
JavaScript
1
2
1
df["gen"] = df["gen"].apply(low)
2