0

With the following DataFrame:

baz = pd.DataFrame({("a", "b"): [1, 2, 3], "g": [11, 12, 13]})

if I try to select columns from it like this:

baz[[("a", "b"), "g"]]

everything is fine. If, however, I access it like this:

baz[["g", ("a", "b")]]

I get an error:

ValueError: setting an array element with a sequence

Is this a bug, or something I'm doing wrong? I'm using pandas 0.22.0, the same happens with 0.20.1

Edit: This is not the same as Numpy ValueError: setting an array element with a sequence. This message may appear without the existing of a sequence? since I'm not explicitly setting anything per se. (Although it may of course relate to the same underlying bug; I have no idea.)

acrophobia
  • 924
  • 7
  • 22
  • This *appears* to be a bug. Or, at the very least, inconsistent treatment. One way that works fine is to use `frozenset({'a', 'b'})` instead of `('a', 'b')`. This may or may not suit for your use case. – jpp Mar 31 '18 at 20:04
  • Possible duplicate of [Numpy ValueError: setting an array element with a sequence. This message may appear without the existing of a sequence?](https://stackoverflow.com/questions/13310347/numpy-valueerror-setting-an-array-element-with-a-sequence-this-message-may-app) – Stephen Rauch Mar 31 '18 at 20:17
  • This is a numpy thing. There is commentary at the dupe about a workaround that I tested successfully. – Stephen Rauch Mar 31 '18 at 20:18
  • I understand the problem is due to `numpy` (and that's where the "fix" lies). But I thought the whole point of `pandas` overhead is to deal with all the edge cases / provide flexibility versus strict `numpy` requirements. – jpp Mar 31 '18 at 20:38
  • Sure you might call it a bug but why are we using a tuple as a column name here? – Anton vBR Apr 03 '18 at 21:02

0 Answers0