#NEWLINE# def test_pivot_columns_lexsorted( self ) : #NEWLINE# #INDENT# n = 10000 #NEWLINE# dtype = np . dtype ( [ ( 'Index' , object ) , ( 'Symbol' , object ) , ( 'Year' , int ) , ( 'Month' , int ) , ( 'Day' , int ) , ( 'Quantity' , int ) , ( 'Price' , float ) ] ) #NEWLINE# products = np . array ( [ ( 'SP500' , 'ADBE' ) , ( 'SP500' , 'NVDA' ) , ( 'SP500' , 'ORCL' ) , ( 'NDQ100' , 'AAPL' ) , ( 'NDQ100' , 'MSFT' ) , ( 'NDQ100' , 'GOOG' ) , ( 'FTSE' , 'DGE.L' ) , ( 'FTSE' , 'TSCO.L' ) , ( 'FTSE' , 'GSK.L' ) ] , dtype = [ ( 'Index' , object ) , ( 'Symbol' , object ) ] ) #NEWLINE# items = np . empty ( n , dtype = dtype ) #NEWLINE# iproduct = np . random . randint ( 0 , len ( products ) , n ) #NEWLINE# items [ 'Index' ] = products [ 'Index' ] [ iproduct ] #NEWLINE# items [ 'Symbol' ] = products [ 'Symbol' ] [ iproduct ] #NEWLINE# dr = pd . date_range ( date ( 2000 , 1 , 1 ) , date ( 2010 , 12 , 31 ) ) #NEWLINE# dates = dr [ np . random . randint ( 0 , len ( dr ) , n ) ] #NEWLINE# items [ 'Year' ] = dates . year #NEWLINE# items [ 'Month' ] = dates . month #NEWLINE# items [ 'Day' ] = dates . day #NEWLINE# items [ 'Price' ] = np . random . lognormal ( 4.0 , 2.0 , n ) #NEWLINE# df = DataFrame ( items ) #NEWLINE# pivoted = df . pivot_table ( 'Price' , index = [ 'Month' , 'Day' ] , columns = [ 'Index' , 'Symbol' , 'Year' ] , aggfunc = 'mean' ) #NEWLINE# self . assertTrue ( pivoted . columns . is_monotonic )