Skip to content

Instantly share code, notes, and snippets.

@zhusimaji
Created October 28, 2017 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhusimaji/32dbb13ba9a3ba7fc86ac7bf3522a493 to your computer and use it in GitHub Desktop.
Save zhusimaji/32dbb13ba9a3ba7fc86ac7bf3522a493 to your computer and use it in GitHub Desktop.
pd
data=pd.DataFrame([[2010,'auto'],[2010,'haha'],[2011,'haha'],[2012,'md']],columns=['year','type'])
data['typecnt']=np.ones(data.shape[0])
data.groupby(['year','type'])['typecnt'].count()
输出
year type
2010 auto 1
haha 1
2011 haha 1
2012 md 1
Name: typecnt, dtype: int64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment