@@ -1300,21 +1300,18 @@ def test_crosstab_normalize(self):
1300
1300
[0.25 , 0.75 ],
1301
1301
[0.4 , 0.6 ]],
1302
1302
index = pd .Index ([1 , 2 , 'All' ],
1303
- name = 'a' ,
1304
- dtype = 'object' ),
1303
+ name = 'a' ),
1305
1304
columns = pd .Index ([3 , 4 ], name = 'b' ))
1306
1305
col_normal_margins = pd .DataFrame ([[0.5 , 0 , 0.2 ], [0.5 , 1.0 , 0.8 ]],
1307
- index = pd .Index ([1 , 2 ], name = 'a' ,
1308
- dtype = 'object' ),
1306
+ index = pd .Index ([1 , 2 ], name = 'a' ),
1309
1307
columns = pd .Index ([3 , 4 , 'All' ],
1310
1308
name = 'b' ))
1311
1309
1312
1310
all_normal_margins = pd .DataFrame ([[0.2 , 0 , 0.2 ],
1313
1311
[0.2 , 0.6 , 0.8 ],
1314
1312
[0.4 , 0.6 , 1 ]],
1315
1313
index = pd .Index ([1 , 2 , 'All' ],
1316
- name = 'a' ,
1317
- dtype = 'object' ),
1314
+ name = 'a' ),
1318
1315
columns = pd .Index ([3 , 4 , 'All' ],
1319
1316
name = 'b' ))
1320
1317
tm .assert_frame_equal (pd .crosstab (df .a , df .b , normalize = 'index' ,
@@ -1361,10 +1358,10 @@ def test_crosstab_normalize(self):
1361
1358
1362
1359
def test_crosstab_norm_margins_with_multiindex (self ):
1363
1360
# GH 15150
1364
- a = np .array (['foo' , 'bar' , 'foo' , 'bar' ,'bar' , 'foo' ])
1365
- b = np .array (['one' , 'one' , 'two' , 'one' ,'two' , 'two' ])
1366
- c = np .array (['dull' , 'shiny' , 'dull' , 'dull' ,'dull' , 'shiny' ])
1367
- d = np .array (['a' , 'a' , 'b' , 'a' ,'b' , 'b' ])
1361
+ a = np .array (['foo' , 'bar' , 'foo' , 'bar' , 'bar' , 'foo' ])
1362
+ b = np .array (['one' , 'one' , 'two' , 'one' , 'two' , 'two' ])
1363
+ c = np .array (['dull' , 'shiny' , 'dull' , 'dull' , 'dull' , 'shiny' ])
1364
+ d = np .array (['a' , 'a' , 'b' , 'a' , 'b' , 'b' ])
1368
1365
expected_col_colnorm = MultiIndex (levels = [['All' , 'dull' , 'shiny' ],
1369
1366
['' , 'a' , 'b' ]],
1370
1367
labels = [[1 , 1 , 2 , 2 , 0 ],
@@ -1399,11 +1396,11 @@ def test_crosstab_norm_margins_with_multiindex(self):
1399
1396
[.33333333 , .33333333 ,
1400
1397
.16666667 , .16666667 ]])
1401
1398
expected_indexnorm = pd .DataFrame (expected_data_indexnorm ,
1402
- index = expected_index_indexnorm ,
1403
- columns = expected_col_indexnorm )
1399
+ index = expected_index_indexnorm ,
1400
+ columns = expected_col_indexnorm )
1404
1401
expected_data_allnorm = np .array ([[0.16666667 , 0. , .16666667 ,
1405
1402
0. , .33333333 ],
1406
- [0. , .16666667 , 0. ,
1403
+ [0. , .16666667 , 0. ,
1407
1404
0. , .16666667 ],
1408
1405
[.16666667 , 0. , 0. ,
1409
1406
0. , .16666667 ],
@@ -1412,15 +1409,15 @@ def test_crosstab_norm_margins_with_multiindex(self):
1412
1409
[0.33333333 , .33333333 , .16666667 ,
1413
1410
.16666667 , 1. ]])
1414
1411
expected_allnorm = pd .DataFrame (expected_data_allnorm ,
1415
- index = expected_index_indexnorm ,
1416
- columns = expected_col_colnorm )
1412
+ index = expected_index_indexnorm ,
1413
+ columns = expected_col_colnorm )
1417
1414
1418
- result_colnorm = pd .crosstab ([a , b ], [c ,d ], normalize = 'columns' ,
1415
+ result_colnorm = pd .crosstab ([a , b ], [c , d ], normalize = 'columns' ,
1419
1416
margins = True )
1420
- result_indexnorm = pd .crosstab ([a , b ], [c ,d ], normalize = 'index' ,
1421
- margins = True )
1422
- result_allnorm = pd .crosstab ([a , b ], [c ,d ], normalize = 'all' ,
1417
+ result_indexnorm = pd .crosstab ([a , b ], [c , d ], normalize = 'index' ,
1423
1418
margins = True )
1419
+ result_allnorm = pd .crosstab ([a , b ], [c , d ], normalize = 'all' ,
1420
+ margins = True )
1424
1421
1425
1422
tm .assert_frame_equal (result_colnorm , expected_colnorm )
1426
1423
tm .assert_frame_equal (result_indexnorm , expected_indexnorm )
0 commit comments