jean paul get all the unique values from a pandas series exept for nan in python

To get all the unique values from a pandas series, except for NaN, you can use the dropna() method along with the unique() method. Here's an example:

main.py
import pandas as pd

# Creating a sample series
s = pd.Series([1, 2, 2, 3, 3, float('NaN'), 4, 5, 5, float('NaN')])

# Getting all unique values except for NaN
unique_values = s.dropna().unique()

print(unique_values)
218 chars
10 lines

Output:

main.py
[1. 2. 3. 4. 5.]
17 chars
2 lines

First, we use the dropna() method to remove all the NaN values from the series. Then we use the unique() method to get all the unique values from the series.

gistlibby LogSnag