Apr-18-2018, 11:35 PM
(Apr-18-2018, 07:33 AM)garikhgh0 Wrote: the Dtaframe.pivot_table does not work correctly
Was trying to reproduce, but couldn't find the error:
1 2 3 |
import pandas as pd data = pd.DataFrame({ 'x' : pd.np.random.randint( 0 , 100 , 1000 ), 'y' : pd.np.random.choice([ 'a' , 'b' , 'c' ], 1000 )}) pd.pivot_table(data, aggfunc = pd.np. sum , values = 'x' , columns = [ 'y' ]) |
Output:y a b c
x 16924 16650 16377
1 2 3 |
# change column type data.y = data.y.astype( 'category' ) pd.pivot_table(data, aggfunc = pd.np. sum , values = 'x' , columns = [ 'y' ]) |
Output:y a b c
x 16924 16650 16377