Last active
November 20, 2015 05:55
-
-
Save nhatbui/8dff90e610cdc47cfc68 to your computer and use it in GitHub Desktop.
Count Unique from Pandas DataFrame
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
d = { | |
'a': ['1','1','2','2','2','3'], | |
'b': ['green', 'blue','yellow','yellow','blue','green'] | |
} | |
df = pd.DataFrame.from_dict(d) | |
df_count = pd.crosstab(df['a'], df['b']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Motivation: Is there a Pandas-only way to take a DataFrame, group by a column, and count all unique values of another column?