Pandas dataframe.nunique() Method Last Updated : 29 Mar, 2023 Comments Improve Suggest changes Like Article Like Report Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas DataFrame.nunique Syntax Pandas dataframe.nunique() function returns a Series with a number of distinct observations over the requested axis. If we set the value of the axis to 0, then it finds the total number of unique observations over the index axis. If we set the value of the axis to 1, then it finds the total number of unique observations over the column axis. It also provides the feature to exclude the NaN values from the count of unique numbers. Syntax: DataFrame.nunique(axis=0, dropna=True) Parameters: axis : {0 or ‘index’, 1 or ‘columns’}, default 0dropna : Don’t include NaN in the counts. Returns : nunique : Series Pandas DataFrame nunique() Method Example 1: Use nunique() function to find the number of unique values over the column axis. Python3 # importing pandas as pd import pandas as pd # Creating the first dataframe df = pd.DataFrame({"A":[14, 4, 5, 4, 1], "B":[5, 2, 54, 3, 2], "C":[20, 20, 7, 3, 8], "D":[14, 3, 6, 2, 6]}) # Print the dataframe df Output: Let's use the dataframe.nunique() function to find the unique values across the column axis. Python3 # find unique values df.nunique(axis=1) Output: As we can see in the output, the function prints the total no. of unique values in each row. Example 2: Use nunique() function to find the number of unique values over the index axis in a Dataframe. The Dataframe contains NaN values. Python3 # importing pandas as pd import pandas as pd # Creating the first dataframe df = pd.DataFrame({"A": ["Sandy", "alex", "brook", "kelly", np.nan], "B": [np.nan, "olivia", "olivia", "", "amanda"], "C": [20 + 5j, 20 + 5j, 7, None, 8], "D": [14.8, 3, None, 6, 6]}) # apply the nunique() function df.nunique(axis=0, dropna=True) Output: The function is treating the empty string as a unique value in column 2. Comment More infoAdvertise with us Next Article Pandas dataframe.nunique() Method S Shubham__Ranjan Follow Improve Article Tags : Technical Scripter Python Python-pandas Python pandas-dataFrame Pandas-DataFrame-Methods +1 More Practice Tags : python Similar Reads Pandas Functions in Python: A Toolkit for Data Analysis Pandas is one of the most used libraries in Python for data science or data analysis. It can read data from CSV or Excel files, manipulate the data, and generate insights from it. Pandas can also be used to clean data, filter data, and visualize data. Whether you are a beginner or an experienced pro 6 min read Pandas Read CSV in Python CSV files are the Comma Separated Files. It allows users to load tabular data into a DataFrame, which is a powerful structure for data manipulation and analysis. To access data from the CSV file, we require a function read_csv() from Pandas that retrieves data in the form of the data frame. Hereâs a 6 min read Pandas Dataframe/Series.head() method - Python The head() method structure and contents of our dataset without printing everything. By default it returns the first five rows but this can be customized to return any number of rows. It is commonly used to verify that data has been loaded correctly, check column names and inspect the initial record 3 min read Pandas Dataframe/Series.tail() method - Python The tail() method allows us to quickly preview the last few rows of a DataFrame or Series. This method is useful for data exploration as it helps us to inspect the bottom of the dataset without printing everything. By default it returns the last five rows but this can be customized to return any num 3 min read Pandas Dataframe.sample() | Python Pandas DataFrame.sample() function is used to select randomly rows or columns from a DataFrame. It proves particularly helpful while dealing with huge datasets where we want to test or analyze a small representative subset. We can define the number or proportion of items to sample and manage randomn 2 min read Python | Pandas dataframe.info() When working with data in Python understanding the structure and content of our dataset is important. The dataframe.info() method in Pandas helps us in providing a concise summary of our DataFrame and it quickly assesses its structure, identify issues like missing values and optimize memory usage.Ke 2 min read Pandas DataFrame dtypes Property | Find DataType of Columns Pandas DataFrame is a two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Pandas DataFrame.dtypes attribute returns a series with the data type of each column.Example:Pythonimport pandas as pd df = pd.DataFrame({'Weight': [45, 88, 56, 3 min read Pandas df.size, df.shape and df.ndim Methods Understanding structure of our data is an important step in data analysis and Pandas helps in making this easy with its df.size, df.shape and df.ndim functions. They allow us to identify the size, shape and dimensions of our DataFrame. In this article, we will see how to implement these functions in 2 min read Pandas DataFrame describe() Method The describe() method in Pandas generates descriptive statistics of DataFrame columns which provides key metrics like mean, standard deviation, percentiles and more. It works with numeric data by default but can also handle categorical data which offers insights like the most frequent value and the 4 min read Python | Pandas Series.unique() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages, and makes importing and analyzing data much easier. While analyzing the data, many times the user wants to see the unique values in a par 1 min read Like