Pandas Count distinct Values of one column depend on another column
Count distinct equivalent:
import pandas as pd df = pd.DataFrame({'DateOfBirth': ['1986-11-11', '1999-05-12', '1976-01-01', '1986-06-01', '1983-06-04', '1990-03-07', '1999-07-09'], 'State': ['NY', 'TX', 'FL', 'AL', 'AK', 'TX', 'TX'] }, index=['Jane', 'Nick', 'Aaron', 'Penelope', 'Dean', 'Christina', 'Cornelia']) print(df.groupby('State').DateOfBirth.nunique())
C:\pandas>python example60.py State AK 1 AL 1 FL 1 NY 1 TX 3 Name: DateOfBirth, dtype: int64 C:\pandas>
2018-10-14T00:51:22+05:30
2018-10-14T00:51:22+05:30
Amit Arora
Amit Arora
Python Programming Tutorial
Python
Practical Solution