I would like that when viewing my DataFrame I will see all values of the multiIndex, including when subsequent rows have the same index for one of the levels. Here is an example:
arrays = [['20', '50', '20', '20'],['N/A', 'N/A', '10', '30']]
tuples = list(zip(*arrays))
index = pd.MultiIndex.from_tuples(tuples, names=['Jim', 'Betty'])
pd.DataFrame([np.random.rand(1)]*4,index=index)
The output is:
0
Jim Betty
20 N/A 0.954973
50 N/A 0.954973
20 10 0.954973
30 0.954973
I would like to have a 20 also in the south-west corner. That is, I would like my DataFrame to be:
0
Jim Betty
20 N/A 0.954973
50 N/A 0.954973
20 10 0.954973
20 30 0.954973
Is Pandas capable of doing that?
As previously mentioned, Pandas iloc is primarily integer position based. That is, it can be used to index a dataframe using 0 to length-1 whether it's the row or column indices.
You need set display.multi_sparse
to False
:
#if need temporary use option
with pd.option_context('display.multi_sparse', False):
print (df)
0
Jim Betty
20 N/A 0.201643
50 N/A 0.201643
20 10 0.201643
20 30 0.201643
If this display option is required throughout a notebook, the option can be set once and for all as follows:
# if permanent use
import pandas as pd
pd.options.display.multi_sparse = False
Documentation:
display.multi_sparse
True
“Sparsify” MultiIndex display (don’t display repeated elements in outer levels within groups)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With