1

I have a dataframe which is organized similar to this

enter image description here

I am trying to make a new column which details if the GUID matches and the 'DL', 'DRI', 'DS' columns match. So from the image above the new column would have picked up that this data is a match.

I've tried:

cols = {['DL','DRI','DS']}
df['match'] = df[cols].eq(df.col1.shift())

But am getting 'TypeError: unhashable type: 'list''

3
  • Don;t post images of data, use text Commented Nov 29, 2019 at 6:24
  • How do you plan to let a column contain information about multiple rows? Commented Nov 29, 2019 at 6:28
  • Its more like it checks the row above because earlier in the script I've sorted the set by column A Commented Nov 29, 2019 at 6:29

2 Answers 2

1

Maybe this is what you want. Maybe you should rephrase your question because it isn't clear what you actually want.

df = pd.DataFrame({'GUID':['00059','00059','123'], 'DL':['','','123'], 'DRI':[True,True,True], 'DS':['','','123'], 'Model':['asd','qwe','123']})
df

    GUID   DL   DRI   DS Model
0  00059       True        asd
1  00059       True        qwe
2    123  123  True  123   123

df['match'] = df.duplicated(['GUID', 'DL', 'DRI', 'DS'], keep=False)
df

    GUID   DL   DRI   DS Model  match
0  00059       True        asd   True
1  00059       True        qwe   True
2    123  123  True  123   123  False
Sign up to request clarification or add additional context in comments.

1 Comment

yep that worked luigigi, thanks a lot. I made it work by combining the three column values in a new column then removing where they matched but this is much better.
1

cols = {['DL','DRI','DS']}

is in the wrong format, it should be:

cols = [['DL','DRI','DS']] 

1 Comment

didn't seem to do the trick, still coming out as false with the change

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.