Re: pandas loc on str lower for column comparison

2019-09-10 Thread Piet van Oostrum
Sayth Renshaw writes: >> >> That actually creates another error. >> >> 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/indexi

Re: pandas loc on str lower for column comparison

2019-09-09 Thread Sayth Renshaw
On Tuesday, 10 September 2019 12:56:36 UTC+10, Sayth Renshaw wrote: > On Friday, 6 September 2019 07:52:56 UTC+10, Piet van Oostrum wrote: > > Piet van Oostrum <> writes: > > > > > That would select ROWS 0,1,5,6,7, not columns. > > > To select columns 0,1,5,6,7, use two-dimensional indexes > > >

Re: pandas loc on str lower for column comparison

2019-09-09 Thread Sayth Renshaw
On Friday, 6 September 2019 07:52:56 UTC+10, Piet van Oostrum wrote: > Piet van Oostrum <> 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

Re: pandas loc on str lower for column comparison

2019-09-05 Thread Sayth Renshaw
That is actually consistent with Excel row, column. Can see why it works that way then. Thanks -- https://mail.python.org/mailman/listinfo/python-list

Re: pandas loc on str lower for column comparison

2019-09-05 Thread Piet van Oostrum
Piet van Oostrum 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']

Re: pandas loc on str lower for column comparison

2019-09-05 Thread Piet van Oostrum
Sayth Renshaw writes: > On Sunday, 1 September 2019 10:48:54 UTC+10, Sayth Renshaw wrote: >> I've created a share doc same structure anon data from my google drive. >> >> https://drive.google.com/file/d/0B28JfFTPNr_lckxQRnFTRF9UTEFYRUVqRWxCNVd1VEZhcVNr/view?usp=sharing >> >> Sayth > > I tried

Re: pandas loc on str lower for column comparison

2019-09-04 Thread Sayth Renshaw
On Sunday, 1 September 2019 10:48:54 UTC+10, Sayth Renshaw wrote: > I've created a share doc same structure anon data from my google drive. > > https://drive.google.com/file/d/0B28JfFTPNr_lckxQRnFTRF9UTEFYRUVqRWxCNVd1VEZhcVNr/view?usp=sharing > > Sayth I tried creating the df1 dataframe by usin

Re: pandas loc on str lower for column comparison

2019-09-01 Thread Sayth Renshaw
I've created a share doc same structure anon data from my google drive. https://drive.google.com/file/d/0B28JfFTPNr_lckxQRnFTRF9UTEFYRUVqRWxCNVd1VEZhcVNr/view?usp=sharing Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: pandas loc on str lower for column comparison

2019-08-31 Thread Sayth Renshaw
On Sunday, 1 September 2019 05:19:34 UTC+10, Piet van Oostrum wrote: > Sayth Renshaw writes: > > > 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. > >

Re: pandas loc on str lower for column comparison

2019-08-31 Thread Piet van Oostrum
Sayth Renshaw writes: > 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. > What do you mean by testing df1? And could it be that 'Current Team' is spelled diff

Re: pandas loc on str lower for column comparison

2019-08-30 Thread Piet van Oostrum
Sayth Renshaw 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

Re: pandas loc on str lower for column comparison

2019-08-29 Thread Sayth Renshaw
On Friday, 30 August 2019 00:49:32 UTC+10, Piet van Oostrum wrote: > Piet van Oostrum writes: > > > So the correct way to do this is to make df1 a copy rather than a view. > > > > df1 = df.loc[:, ('UID','Name','New Leader','Current Team', 'New Team')] > > Or maybe even make an explicit copy: >

Re: pandas loc on str lower for column comparison

2019-08-29 Thread Sayth Renshaw
On Friday, 30 August 2019 00:49:32 UTC+10, Piet van Oostrum wrote: > Piet van Oostrum > > > So the correct way to do this is to make df1 a copy rather than a view. > > > > df1 = df.loc[:, ('UID','Name','New Leader','Current Team', 'New Team')] > > Or maybe even make an explicit copy: > > df1 =

Re: pandas loc on str lower for column comparison

2019-08-29 Thread Piet van Oostrum
Piet van Oostrum writes: > So the correct way to do this is to make df1 a copy rather than a view. > > df1 = df.loc[:, ('UID','Name','New Leader','Current Team', 'New Team')] Or maybe even make an explicit copy: df1 = df[['UID','Name','New Leader','Current Team', 'New Team']].copy() -- Piet va

Re: pandas loc on str lower for column comparison

2019-08-29 Thread Piet van Oostrum
Sayth Renshaw writes: > 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 > > impo

pandas loc on str lower for column comparison

2019-08-28 Thread Sayth Renshaw
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("Melb