MultiIndex.from_tuples returns an Index when all tuples are length 1
See original GitHub issueIn [1]: import pandas as pd
In [2]: pd.MultiIndex.from_tuples([('a',), ('b',)])
Out[2]: Index(['a', 'b'], dtype='object')
This should return a MultiIndex
I think, like
Out[5]:
MultiIndex(levels=[['a', 'b']],
labels=[[0, 1]])
Well, pd.MultiIndex([['a', 'b']], [[0, 1]])
returns the same thing as from_tuples
(an index) so maybe this is intentional.
Trying to figure out if this is intentional or not (this came up in my categorical dtype refactor).
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
pandas.MultiIndex.from_tuples — pandas 1.5.2 documentation
Each tuple is the index of one row/column. Level of sortedness (must be lexicographically sorted by that level). Names for the levels in...
Read more >Pandas list of tuples to MultiIndex - python - Stack Overflow
This will unpack the t_1 elements systematically and output the dataframe in a structure you want. Output: id f g 0 100...
Read more >Python | Pandas MultiIndex.from_tuples() - GeeksforGeeks
Returns : index : MultiIndex. Example #1: Use MultiIndex.from_tuples() function to construct a MultiIndex using python tuples.
Read more >Source code for pyspark.pandas.indexes.multi
MultiIndex.from_tuples : Convert list of tuples to a MultiIndex. ... 'c']}, index=[[1, 2, 3], [4, 5, 6]]).index # doctest: +SKIP MultiIndex([(1, 4), (2,...
Read more >Confused by Multi-Index in Pandas? 9 Essential Operations to ...
1. What's MultiIndex? We have mentioned that single level index uses a ... indicates all the rows' embark_town level (0 -> 'Cherbourg', 1...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+1 for having
MultiIndex.from_whatever
consistently return aMultiIndex
.#14823 seems unrelated, unless I’m missing something These are all the same length (1).
The fix is essentially a one-liner: https://github.com/pandas-dev/pandas/compare/master...TomAugspurger:multiindex-squeeze?expand=1#diff-4ffd1c69d47e0ac9f2de4f9e3e4a118cR102