简体   繁体   中英

From Pandas Dataframe find unique values in column and see if those values have the same values in another column

I want to get all unique values from one column, and see if each unique value have the same values in another column. below I have a data frame and I am looking for unique values in the first column {2,3,4} . And I am trying to see if these values have unique values in same position in the last column.

By looking, clearly only 3 values in the first column has only the same values ( 4 ) in corresponding position in the last column . So (3, 4) matches. How could I achieve this paring (3, 4) in Pandas ? Unique values in column 1 must only have unique values in column 4!

2  2  1  4
2  3  4  4
3  4  3  4
3  5  8  4
2  6  9  2
4  1  6  2
4  4  1  4 
2  4  5  2

I do not quit clear the question , since column1 have match 2 and 4 with column 4 . thanks Igor's comment.

df.groupby('c1').c4.unique().loc[lambda x : x.str.len()==1].str[0]
Out[116]: 
c1
3    4
Name: c4, dtype: int64

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM