5 examples of 'unique values in column pandas' in Python

Every line of 'unique values in column 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
Important

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

91def to_unique(self, column_or_columns):
92 self.__convert_column(column_or_columns, FType.unique, None)
242def unique(self, values):
243 """
244 Return unique values of Series object. Uniques are returned
245 in order of appearance.
246 Hash table-based unique, therefore does NOT sort.
247
248 Parameters
249 ----------
250 values : array, list, series or dataframe.
251 The set of values to identify unique occurrences.
252
253 Returns
254 -------
255 ndarray or ExtensionArray
256 The unique values returned as a NumPy array.
257
258 References
259 ----------
260 https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.unique.html
261
262 """
263 operation = begin_operation('unique')
264 unique_ = self._data.unique(values)
265 self.last_operation = end_operation(operation)
266
267 return unique_
280def nunique(self):
281 """
282 Find the number of unique values in each column
283
284 Returns
285 -------
286 A DataFrame
287 """
288 pass
49def remove_duplicates(df_or_series):
50 """ Remove duplicate rows or values by keeping the first of each duplicate.
51
52 Parameters
53 ----------
54 df_or_series : :any:`pandas.DataFrame` or :any:`pandas.Series`
55 Pandas object from which to drop duplicate index values.
56
57 Returns
58 -------
59 deduplicated : :any:`pandas.DataFrame` or :any:`pandas.Series`
60 The deduplicated pandas object.
61 """
62 # CalTrack 2.3.2.2
63 return df_or_series[~df_or_series.index.duplicated(keep="first")]

Related snippets