@@ -1266,21 +1266,18 @@ def test_crosstab_normalize(self):
1266
1266
[0.25 , 0.75 ],
1267
1267
[0.4 , 0.6 ]],
1268
1268
index = pd .Index ([1 , 2 , 'All' ],
1269
- name = 'a' ,
1270
- dtype = 'object' ),
1269
+ name = 'a' ),
1271
1270
columns = pd .Index ([3 , 4 ], name = 'b' ))
1272
1271
col_normal_margins = pd .DataFrame ([[0.5 , 0 , 0.2 ], [0.5 , 1.0 , 0.8 ]],
1273
- index = pd .Index ([1 , 2 ], name = 'a' ,
1274
- dtype = 'object' ),
1272
+ index = pd .Index ([1 , 2 ], name = 'a' ),
1275
1273
columns = pd .Index ([3 , 4 , 'All' ],
1276
1274
name = 'b' ))
1277
1275
1278
1276
all_normal_margins = pd .DataFrame ([[0.2 , 0 , 0.2 ],
1279
1277
[0.2 , 0.6 , 0.8 ],
1280
1278
[0.4 , 0.6 , 1 ]],
1281
1279
index = pd .Index ([1 , 2 , 'All' ],
1282
- name = 'a' ,
1283
- dtype = 'object' ),
1280
+ name = 'a' ),
1284
1281
columns = pd .Index ([3 , 4 , 'All' ],
1285
1282
name = 'b' ))
1286
1283
tm .assert_frame_equal (pd .crosstab (df .a , df .b , normalize = 'index' ,
@@ -1327,10 +1324,10 @@ def test_crosstab_normalize(self):
1327
1324
1328
1325
def test_crosstab_norm_margins_with_multiindex (self ):
1329
1326
# GH 15150
1330
- a = np .array (['foo' , 'bar' , 'foo' , 'bar' ,'bar' , 'foo' ])
1331
- b = np .array (['one' , 'one' , 'two' , 'one' ,'two' , 'two' ])
1332
- c = np .array (['dull' , 'shiny' , 'dull' , 'dull' ,'dull' , 'shiny' ])
1333
- d = np .array (['a' , 'a' , 'b' , 'a' ,'b' , 'b' ])
1327
+ a = np .array (['foo' , 'bar' , 'foo' , 'bar' , 'bar' , 'foo' ])
1328
+ b = np .array (['one' , 'one' , 'two' , 'one' , 'two' , 'two' ])
1329
+ c = np .array (['dull' , 'shiny' , 'dull' , 'dull' , 'dull' , 'shiny' ])
1330
+ d = np .array (['a' , 'a' , 'b' , 'a' , 'b' , 'b' ])
1334
1331
expected_col_colnorm = MultiIndex (levels = [['All' , 'dull' , 'shiny' ],
1335
1332
['' , 'a' , 'b' ]],
1336
1333
labels = [[1 , 1 , 2 , 2 , 0 ],
@@ -1365,11 +1362,11 @@ def test_crosstab_norm_margins_with_multiindex(self):
1365
1362
[.33333333 , .33333333 ,
1366
1363
.16666667 , .16666667 ]])
1367
1364
expected_indexnorm = pd .DataFrame (expected_data_indexnorm ,
1368
- index = expected_index_indexnorm ,
1369
- columns = expected_col_indexnorm )
1365
+ index = expected_index_indexnorm ,
1366
+ columns = expected_col_indexnorm )
1370
1367
expected_data_allnorm = np .array ([[0.16666667 , 0. , .16666667 ,
1371
1368
0. , .33333333 ],
1372
- [0. , .16666667 , 0. ,
1369
+ [0. , .16666667 , 0. ,
1373
1370
0. , .16666667 ],
1374
1371
[.16666667 , 0. , 0. ,
1375
1372
0. , .16666667 ],
@@ -1378,15 +1375,15 @@ def test_crosstab_norm_margins_with_multiindex(self):
1378
1375
[0.33333333 , .33333333 , .16666667 ,
1379
1376
.16666667 , 1. ]])
1380
1377
expected_allnorm = pd .DataFrame (expected_data_allnorm ,
1381
- index = expected_index_indexnorm ,
1382
- columns = expected_col_colnorm )
1378
+ index = expected_index_indexnorm ,
1379
+ columns = expected_col_colnorm )
1383
1380
1384
- result_colnorm = pd .crosstab ([a , b ], [c ,d ], normalize = 'columns' ,
1381
+ result_colnorm = pd .crosstab ([a , b ], [c , d ], normalize = 'columns' ,
1385
1382
margins = True )
1386
- result_indexnorm = pd .crosstab ([a , b ], [c ,d ], normalize = 'index' ,
1387
- margins = True )
1388
- result_allnorm = pd .crosstab ([a , b ], [c ,d ], normalize = 'all' ,
1383
+ result_indexnorm = pd .crosstab ([a , b ], [c , d ], normalize = 'index' ,
1389
1384
margins = True )
1385
+ result_allnorm = pd .crosstab ([a , b ], [c , d ], normalize = 'all' ,
1386
+ margins = True )
1390
1387
1391
1388
tm .assert_frame_equal (result_colnorm , expected_colnorm )
1392
1389
tm .assert_frame_equal (result_indexnorm , expected_indexnorm )
0 commit comments