I have a dataframe like this:
| Name | Flag | part1 | part2 | part3 | part4 | part5 | part6 |
|---|---|---|---|---|---|---|---|
| Company1 | Y | Paper | Machinery | IT | Machinery | None | None |
| Company2 | N | IT | Business | Paper | None | None | None |
| Company3 | N | Bio | Bio | Trades | None | None | None |
| Company4 | N | Air | Communication | Oil | Oil | Oil | None |
| Company5 | Y | Business | Oil | Air | Food | None | None |
| Company6 | N | Food | Business | Paper | Bio | Air | Paper |
I need to get a new column "Result" where I compare all values in columns part1 - part6 and if text in any two columns are identical - the result is true and vice versa. It has to be like this:
| Name | Flag | part1 | part2 | part3 | part4 | part5 | part6 | Result |
|---|---|---|---|---|---|---|---|---|
| Company1 | Y | Paper | Machinery | IT | Machinery | None | None | True |
| Company2 | N | IT | Business | Paper | None | None | None | False |
| Company3 | N | Bio | Bio | Trades | None | None | None | True |
| Company4 | N | Air | Communication | Oil | Oil | Oil | None | True |
| Company5 | Y | Business | Oil | Air | Food | None | None | False |
| Company6 | N | Food | Business | Paper | Bio | Air | Paper | True |
Is there any simple way to do it? I tried something like this:
df['Result'] = (df['part1']==df['part2']) | (df['part1']==df['part3']) | (df['part1']==df['part4']) | (df['part1']==df['part5']) | (df['part2']==df['part3']) | (df['part2']==df['part4']) | (df['part2']==df['part5']) |(df['part3']==df['part4']) | (df['part3']==df['part5']) | (df['part4']==df['part5']) But this way is too weird and uncomfortable, I believe that it has a better solution. (In my task I have to compare 21 columns)
part1_ind? Or it's typo?