Python Forum
How to show unique names in a table?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to show unique names in a table?
#1
Hi there, I have follow table

State Gender Year Top Name Occurences
0 AK F 1910 Mary 14
1 AK F 1911 Mary 12
2 AK F 1912 Mary 9
3 AK F 1913 Mary 21
4 AK F 1914 Mary 22
5 AK F 1915 Mary 23
6 AK F 1916 Mary 18
7 AK F 1917 Mary 21
8 AK F 1918 Mary 27

I want to see only one column with the names unique
this is my code:

[python[import pandas as pd
babynames = pd.read_csv('TopBabyNamesbyState.csv')
babynames = pd.unique(pd.Series(['Top Name']))
print(babynames)[/python]

With this code I get the number of all rows in the table.
What is the right code?

Thank you!
J
Reply
#2
To get unique names of the specific column of a data frame, you need to call method .unique(),
e.g. babynames = pd.read_csv('TopBabyNamesbyState.csv')['Top Name'].unique(); If this doesn't work,
the file probably wasn't properly parsed by read_csv (check sep argument and format of your file).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to get first and last row index of each unique names in pandas dataframe SriRajesh 1 4,537 Oct-13-2018, 07:04 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020