osdir.com


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

pandas loc on str lower for column comparison


Hi

I am importing 4 columns into a dataframe from a spreadsheet.

My goal is to create a 5th column with TRUE or False if column 4 (str) matches column 3.

Trying to leverage this answer https://stackoverflow.com/a/35940955/461887

This is my code 

import pandas as pd

xls = pd.ExcelFile("Melbourne.xlsx")
df = xls.parse('Sheet1', skiprows= 4)
df1 = df[['UID','Name','New Leader','Current Team', 'New Team']]
df1['Difference'] = df1['Current Team'].str.lower().str.replace('s/+',"") == df1['New Team'].str.lower().str.replace('s/+',"")

Which gives this error

C:\Users\u369811\AppData\Local\Continuum\anaconda3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

If I update the line to use loc as this I still receive a long error.

df1['Difference'] = df1.loc['Current Team'].str.lower().str.replace('s/+',"") == df1.loc['New Team'].str.lower().str.replace('s/+',"")

What am I missing?

Sayth