I have a DataFrame df1
that looks like this:
A B C
-----------------
1 1 2
2 2 3
5 4 9
I want to get all the unique values in a row. For example 1 and 2 in the first row. 2, 3 in the second row. And 4, 5 and 9 in the third row.
Result can vary, I can imagine a new column that contains a list with unique values or replacing duplicates with None
would be also okay (or something else, maybe there is something more pythonic for this case).
Select Text option from the Formula Type drop down list; Then choose Extract cells with unique values (include the first duplicate) from the Choose a fromula list box; In the right Arguments input section, select a list of cells that you want to extract unique values.
In Excel, there are several ways to filter for unique values—or remove duplicate values: To filter for unique values, click Data > Sort & Filter > Advanced. To remove duplicate values, click Data > Data Tools > Remove Duplicates.
You can get unique values in column (multiple columns) from pandas DataFrame using unique() or Series. unique() functions. unique() from Series is used to get unique values from a single column and the other one is used to get from multiple columns.
Excel has a very useful feature called remove duplicates which can be used on either the whole data set or a single column of data. Copy and paste the column of values which you want to see a list of unique values from to another location. Highlight this list of values.
list(map(set,df.values))
Out[72]: [{1, 2}, {2, 3}, {4, 5, 9}]
In [88]: df.stack().groupby(level=0).apply(lambda x: x.unique().tolist())
Out[88]:
0 [1, 2]
1 [2, 3]
2 [5, 4, 9]
dtype: object
Lets use pd.unique
i.e
df.T.agg([pd.unique])
0 1 2
unique [1, 2] [2, 3] [5, 4, 9]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With