Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- d = ({
- 'Date' : ['1/2/18','1/2/18','1/2/18','1/2/18','1/2/18','1/2/18'],
- 'Val_A' : [1,1,2,2,1,1],
- 'Val_B' : ['X','X','X','X','Y','Y'],
- })
- df = pd.DataFrame(data=d)
- df1 = pd.pivot_table(df, index=['Date'],values=['Val_A','Val_B'],aggfunc= 'count')
- Val_A Val_B
- Date
- 1/2/18 6 6
- Val_X
- Date
- 1/2/18 3
- pd.pivot_table(df.drop_duplicates(), index=['Date'],values=['Val_B'],aggfunc= 'count')
- Val_B
- Date
- 1/2/18 3
- df1 = pd.pivot_table(df.drop_duplicates(), index=['Date'],values=['Val_A','Val_B'],aggfunc= 'count')
- df.drop_duplicates()
- Date Val_A Val_B
- 0 1/2/18 1 X
- 2 1/2/18 2 X
- 4 2/2/18 1 Y
- 6 2/2/18 2 Y
- df.groupby(['Date', 'Val_A', 'Val_B']).size().reset_index()
- Date Val_A Val_B 0
- 0 1/2/18 1 X 2
- 1 1/2/18 1 Y 2
- 2 1/2/18 2 X 2
- g = df.groupby(['Date', 'Val_A', 'Val_B'])
- len(g)
- # Out
- 3
- df.drop_duplicates().groupby('Date').Val_A.count().reset_index(name='Val_x')
- Out[1996]:
- Date Val_x
- 0 1/2/18 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement