Skip to content
Advertisement

Pandas dataframe get unique value of a column

I’m trying to get the unique available value for each site. The original pandas dataframe is with three columns:

Site Available Capacity
A 7 20
A 7 20
A 8 20
B 15 35
B 15 35
C 12 25
C 12 25
C 11 25

and I want to get the unique available of each site. The desired table is like below:

Site Unique Available
A 7
8
B 15
C 12
11

Advertisement

Answer

You can get the lists of unique available per site with GroupBy.unique()

JavaScript

Then with explode() you can expand these lists and with reset_index() get the index back to a column:

JavaScript

Otherwise simply get both columns and remove duplicates:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement