AmitDiwan has Published 10744 Articles

Python Pandas - Return a Series containing counts of unique values from Index object sorted in Ascending Order

AmitDiwan

AmitDiwan

Updated on 13-Oct-2021 08:53:42

245 Views

To return a Series containing counts of unique values from Index object sorted in Ascending Order, use the index.value_counts() method with parameter ascending as True.At first, import the required libraries -import pandas as pdCreating Pandas index −index = pd.Index([50, 10, 70, 110, 90, 50, 110, 90, 30]) Display the Pandas ... Read More

Python Pandas - Return a Series containing counts of unique values from Index object

AmitDiwan

AmitDiwan

Updated on 13-Oct-2021 08:51:00

317 Views

To return a Series containing counts of unique values from Index object, use the index.value_counts() method in Pandas.At first, import the required libraries -import pandas as pdCreating Pandas index −index = pd.Index([50, 10, 70, 110, 90, 50, 110, 90, 30]) Display the Pandas index −print("Pandas Index...", index)Count of unique values ... Read More

Python Pandas - Return number of unique elements in the Index object

AmitDiwan

AmitDiwan

Updated on 13-Oct-2021 08:48:01

123 Views

To return number of unique elements in the Index object, use the index.nunique() method in Pandas. At first, import the required libraries −import pandas as pdCreating Pandas index −index = pd.Index([50, 10, 70, 110, 90, 50, 110, 90, 30]) Display the Pandas index −print("Pandas Index...", index)Get the number of unique ... Read More

Python Pandas - Return unique values in the index

AmitDiwan

AmitDiwan

Updated on 13-Oct-2021 08:45:34

4K+ Views

To return unique values in the index, use the index.unique() method in Pandas. At first, import the required libraries -import pandas as pdCreating Pandas index −index = pd.Index([10, 50, 70, 10, 90, 50, 10, 30]) Display the Pandas index −print("Pandas Index...", index)Get the unique values from the index. Unique values ... Read More

Python Pandas - Mask and replace NaNs with a specific value

AmitDiwan

AmitDiwan

Updated on 13-Oct-2021 08:12:26

1K+ Views

To mask and replace NaNs with a specific value, use the index.putmask() method. Within that, set the index.isna() method.At first, import the required libraries -import pandas as pd import numpy as npCreating Pandas index with some NaNs −index = pd.Index([5, 65, 10, np.nan, 75, np.nan]) Display the Pandas index −print("Pandas ... Read More

Python Pandas - Return a new Index of the values set with the mask

AmitDiwan

AmitDiwan

Updated on 13-Oct-2021 08:10:32

392 Views

To return a new Index of the values set with the mask, use the index.putmask() method in Pandas. At first, import the required libraries −import pandas as pdCreating Pandas index −index = pd.Index([5, 65, 10, 17, 75, 40]) Display the Pandas index −print("Pandas Index...", index)Mask and place index values less ... Read More

Python Pandas - Return a new Index of the values selected by the indices

AmitDiwan

AmitDiwan

Updated on 13-Oct-2021 08:07:57

131 Views

To return a new Index of the values selected by the indices, use the index.take() method in Pandas. At first, import the required libraries -import pandas as pdCreating Pandas index −index = pd.Index(['Electronics', 'Accessories', 'Decor', 'Books', 'Toys'], name ='Products') Display the Pandas index −print("Pandas Index...", index)Getting a new index of ... Read More

Python Pandas - Replace index values where the condition is False

AmitDiwan

AmitDiwan

Updated on 13-Oct-2021 07:59:20

257 Views

To replace index values where the condition is False, use the index.isin() method in Pandas. At first, import the required libraries −import pandas as pdCreating Pandas index −index = pd.Index(['Electronics', 'Accessories', 'Decor', 'Books', 'Toys'], name ='Products') Display the Pandas index −print("Pandas Index...", index)Replace values where condition is False. Here, except ... Read More

Python - Repeat each element of a Pandas Series in a dissimilar way

AmitDiwan

AmitDiwan

Updated on 13-Oct-2021 07:52:42

172 Views

To repeat each element of a Pandas Series in a dissimilar way, use the index.repeat() method. At first, import the required libraries -import pandas as pdCreating Pandas index −index = pd.Index(['Car', 'Bike', 'Airplane', 'Ship'], name ='Transport') Display the Pandas index −print("Pandas Index...", index)Repeat each element of the index in a ... Read More

Python Pandas - Repeat elements of an Index

AmitDiwan

AmitDiwan

Updated on 13-Oct-2021 07:50:28

507 Views

To repeat elements of an Index, use the index.repeat() method in Pandas. Set the number of repetitions as an argument. At first, import the required libraries −import pandas as pdCreating Pandas index −index = pd.Index(['Car', 'Bike', 'Airplane', 'Ship', 'Truck', 'Suburban'], name ='Transport') Display the Pandas index −print("Pandas Index...", index)Repeat elements ... Read More

Advertisements