user3489713
user3489713

Reputation: 3

Lowercase in loop doesn't work

This code works (in the scheme of my program)

name_list = []

for pmodel in Ndf["Purchase_1_Model"]:  
    name = pmodel.split(' ')[0]     
    name_list.append(name)

Ndf['Series_name'] = name_list

What I don't understand is why this does nothing additional

name_list = []

for pmodel in Ndf["Purchase_1_Model"]:  
    name = pmodel.lower
    name = pmodel.split(' ')[0]     
    name_list.append(name)

Ndf['Series_name'] = name_list

Can anyone offer me any guidance? Thanks

Upvotes: 0

Views: 87

Answers (1)

Edd
Edd

Reputation: 3822

It's because you don't use the lower'd version of pmodel.

You call pmodel.lower and assign this to variable name. You then do split on the original, unmodified pmodel, and assign this over the top of the existing value in name, replacing the version that was lowercase before.

You probably want to do something like the following:

for pmodel in Ndf["Purchase_1_Model"]:  
    lowered = pmodel.lower()
    name = lowered.split(' ')[0]     
    name_list.append(name)

Or simply:

for pmodel in Ndf["Purchase_1_Model"]:    
    name_list.append(pmodel.lower().split(' ')[0])

Upvotes: 1

Related Questions