pandas loc on str lower for column comparison

Piet van Oostrum piet-l at vanoostrum.org
Fri Aug 30 18:22:49 EDT 2019


Sayth Renshaw <flebber.crue at gmail.com> writes:

>
> I have tried both
>
> df1 = df.loc[:, ('UID','Name','New Leader','Current Team', 'New Team')] 
> df1['Difference'] = df1.loc['Current Team'].str.lower().str.strip() ==
> df1.loc['New Team'].str.lower().str.strip()
>
> and 
>
> df1 = df[['UID','Name','New Leader','Current Team', 'New Team']].copy()
> df1['Difference'] = df1.loc['Current Team'].str.lower().str.strip() ==
> df1.loc['New Team'].str.lower().str.strip()
>
> But on both occasions I receive this error.
>
> # KeyError: 'the label [Current Team] is not in the [index]'
>
> if I test df1 before trying to create the new column it works just fine.
>
> Sayth

What does df1.info() produce?
Which versions of numpy, scipy and pandas are you using?

It would be helpful if you could make a copy of the original .xlsx file available.
-- 
Piet van Oostrum <piet-l at vanoostrum.org>
WWW: http://piet.vanoostrum.org/
PGP key: [8DAE142BE17999C4]



More information about the Python-list mailing list