question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MultiIndex.from_tuples returns an Index when all tuples are length 1

See original GitHub issue
In [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:closed
  • Created 6 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
jbrockmendelcommented, Aug 11, 2017

+1 for having MultiIndex.from_whatever consistently return a MultiIndex.

0reactions
TomAugspurgercommented, Aug 6, 2017

#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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found