Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
unstack() on DataFrame of ints with MultiIndex which was sliced casts to float #17845
Code Sample, a copy-pastable example if possible
In : idx = pd.MultiIndex.from_product([['a'], ['A', 'B', 'C', 'D']])[:-1] In : df = pd.DataFrame([[1, 0]]*3, index=idx) In : df.unstack() Out: 0 1 A B C A B C a 1.0 1.0 1.0 0.0 0.0 0.0
Since there is no missing value, no type casting should occur. Notice that even replacing
In : df.unstack(fill_value=3) Out: 0 1 A B C A B C a 1 1 1 0 0 0
IIRC there are several related / like issues to this, see if you can find them. note that (though not as satisfying). Yes in thins case you have a full cartesian product so you know there are no missing values, but generally this is not true.