osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

pandas loc on str lower for column comparison


Piet van Oostrum <piet-l at vanoostrum.org> writes:

> That would select ROWS 0,1,5,6,7, not columns.
> To select columns 0,1,5,6,7, use two-dimensional indexes
>
> df1 = df.iloc[:, [0,1,5,6,7]]
>
> : selects all rows.

And that also solves your original problem.

This statement:

df1['Difference'] = df1.loc['Current Team'].str.lower().str.strip() == df1.loc['New Team'].str.lower().str.strip()

should not use .loc, because then you are selecting rows, not columns, but:

df1['Difference'] = df1['Current Team'].str.lower().str.strip() == df1['New Team'].str.lower().str.strip()
-- 
Piet van Oostrum <piet-l at vanoostrum.org>
WWW: http://piet.vanoostrum.org/
PGP key: [8DAE142BE17999C4]