Is it possible to get unique values from multiple columns? I would like each column to have it's own unique values output via a loop.
df["col A"].unique()
| Col A | Col B |
|---|---|
| 3 | 312 |
| 4 | 6456 |
| 3 | 4 |
| 1 | 4 |
Output
Col A: 3, 4, 1
Col B: 6456, 312, 4
It kinda depends on what you want as output. You can do it like this to get a dict with each column:
unique_vals = {col:df[col].unique() for col in df}
But you probably don't want it as a dataframe like this, because there is no guarantee the amount of unique values is the same for each column.
If you only want to print it it's as simple as:
for col in df:
print(f'{col}: {df[col].unique()}')
.unique()does exactly what you want.df.apply(lambda col: col.unique())but I'm not sure if it will work because each columns probably will have an output of different length