user3682157
user3682157

Reputation: 1695

Using lowercase function on list (Python3, Pandas)

Simple question here:

I have a DF like this

 KW              Score     Group     Size
a big man         7          2        1
Purple cow        3          4        2
for all is Not    2          3        3
There we go       2          1        3
...
Day Late          1          3        2

I want to convert all characters in the KW column to lowercase but my code doesn't seem to work. I'm sure it's something very obvious but what am I doing wrong?

df = xl.parse()
df.head()
df.KW.str.lower()
df1 = df[['KW','Score','Group','Size']]

Upvotes: 1

Views: 176

Answers (1)

EdChum
EdChum

Reputation: 394101

Not sure what your problem is but it should work, you are possibly not assigning the result of the operation to anything:

In [3]:

df = pd.DataFrame({'KW':['Upper case', 'lower case','ALL CAPS']})
df


Out[3]:
           KW
0  Upper case
1  lower case
2    ALL CAPS
In [6]:

df['cleaned'] = df.KW.str.lower()
df
Out[6]:
           KW     cleaned
0  Upper case  upper case
1  lower case  lower case
2    ALL CAPS    all caps

Upvotes: 1

Related Questions