How to use 'nunique pandas' in Python

Every line of 'nunique pandas' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
673def _unique(df, columns=None):
674 if isinstance(columns, str):
675 columns = [columns]
676 if not columns:
677 columns = df.columns.tolist()
678 info = {}
679 for col in columns:
680 values = df[col].dropna().values
681 uniques = np.unique(list(_flatten_list(values))).tolist()
682 info[col] = {'count': len(uniques), 'values': uniques}
683 return info

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

280def nunique(self):
281 """
282 Find the number of unique values in each column
284 Returns
285 -------
286 A DataFrame
287 """
288 pass

Related snippets