@@ -1072,17 +1072,17 @@ def test_margin_dropna(self):
1072
1072
df = pd .DataFrame ({'a' : [1 , 2 , 2 , 2 , 2 , np .nan ],
1073
1073
'b' : [3 , 3 , 4 , 4 , 4 , 4 ]})
1074
1074
actual = pd .crosstab (df .a , df .b , margins = True , dropna = False )
1075
- expected = pd .DataFrame ([[1 , 0 , 1 ], [1 , 3 , 4 ], [2 , 4 , 6 ]])
1076
- expected .index = Index ([1.0 , 2.0 , 'All' ], name = 'a' )
1077
- expected .columns = Index ([3 , 4 , 'All' ], name = 'b' )
1075
+ expected = pd .DataFrame ([[1 , 0 , 1 ], [1 , 3 , 4 ], [0 , 1 , 1 ], [ 2 , 4 , 6 ]])
1076
+ expected .index = Index ([1.0 , 2.0 , np . nan , 'All' ], name = 'a' )
1077
+ expected .columns = Index ([3.0 , 4.0 , 'All' ], name = 'b' )
1078
1078
tm .assert_frame_equal (actual , expected )
1079
1079
1080
1080
df = DataFrame ({'a' : [1 , np .nan , np .nan , np .nan , 2 , np .nan ],
1081
1081
'b' : [3 , np .nan , 4 , 4 , 4 , 4 ]})
1082
1082
actual = pd .crosstab (df .a , df .b , margins = True , dropna = False )
1083
- expected = pd .DataFrame ([[1 , 0 , 1 ], [0 , 1 , 1 ], [1 , 4 , 6 ]])
1084
- expected .index = Index ([1.0 , 2.0 , 'All' ], name = 'a' )
1085
- expected .columns = Index ([3.0 , 4.0 , 'All' ], name = 'b' )
1083
+ expected = pd .DataFrame ([[1 , 0 , 0 , 1 ], [0 , 1 , 0 , 1 ], [0 , 3 , 1 , 4 ], [ 1 , 4 , 1 , 6 ]])
1084
+ expected .index = Index ([1.0 , 2.0 , np . nan , 'All' ], name = 'a' )
1085
+ expected .columns = Index ([3.0 , 4.0 , np . nan , 'All' ], name = 'b' )
1086
1086
tm .assert_frame_equal (actual , expected )
1087
1087
1088
1088
a = np .array (['foo' , 'foo' , 'foo' , 'bar' ,
@@ -1094,20 +1094,20 @@ def test_margin_dropna(self):
1094
1094
1095
1095
actual = pd .crosstab (a , [b , c ], rownames = ['a' ],
1096
1096
colnames = ['b' , 'c' ], margins = True , dropna = False )
1097
- m = MultiIndex .from_arrays ([['one' , 'one' , 'two' , 'two' , 'All' ],
1098
- ['dull' , 'shiny' , 'dull' , 'shiny' , '' ]],
1097
+ m = MultiIndex .from_arrays ([[np . nan , np . nan , 'one' , 'one' , 'two' , 'two' , 'All' ],
1098
+ ['dull' , 'shiny' , 'dull' , 'shiny' , 'dull' , 'shiny' , ' ' ]],
1099
1099
names = ['b' , 'c' ])
1100
- expected = DataFrame ([[1 , 0 , 1 , 0 , 2 ], [2 , 0 , 1 , 1 , 5 ],
1101
- [3 , 0 , 2 , 1 , 7 ]], columns = m )
1100
+ expected = DataFrame ([[0 , 0 , 1 , 0 , 1 , 0 , 2 ], [0 , 1 , 2 , 0 , 1 , 1 , 5 ],
1101
+ [0 , 1 , 3 , 0 , 2 , 1 , 7 ]], columns = m )
1102
1102
expected .index = Index (['bar' , 'foo' , 'All' ], name = 'a' )
1103
1103
tm .assert_frame_equal (actual , expected )
1104
1104
1105
1105
actual = pd .crosstab ([a , b ], c , rownames = ['a' , 'b' ],
1106
1106
colnames = ['c' ], margins = True , dropna = False )
1107
- m = MultiIndex .from_arrays ([['bar' , 'bar' , 'foo' , 'foo' , 'All' ],
1108
- ['one' , 'two' , 'one' , 'two' , '' ]],
1107
+ m = MultiIndex .from_arrays ([['bar' , 'bar' , 'bar' , 'foo' , ' foo' , 'foo' , 'All' ],
1108
+ [np . nan , 'one' , 'two' , np . nan , 'one' , 'two' , '' ]],
1109
1109
names = ['a' , 'b' ])
1110
- expected = DataFrame ([[1 , 0 , 1 ], [1 , 0 , 1 ], [2 , 0 , 2 ], [1 , 1 , 2 ],
1110
+ expected = DataFrame ([[0 , 0 , 0 ], [ 1 , 0 , 1 ], [1 , 0 , 1 ], [ 0 , 1 , 1 ], [2 , 0 , 2 ], [1 , 1 , 2 ],
1111
1111
[5 , 2 , 7 ]], index = m )
1112
1112
expected .columns = Index (['dull' , 'shiny' , 'All' ], name = 'c' )
1113
1113
tm .assert_frame_equal (actual , expected )
0 commit comments