2

Does anyone know why the following code works in python 2.7, but not in python 3?

from pandas import *

df = {'one' : Series([1., 2., 3.], index=['a', 'b', 'c']),
'two' : Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])}
df = DataFrame(df)

df.index[:] = 0

In 2.7, this returns the following:

Index([0, 0, 0, 0], dtype=object)

Whereas in python 3 I get:

Exception: <class 'pandas.core.index.Index'> object is immutable

I have checked the pandas version and it's 0.12.0 in both cases.

My understanding was that the index is immutable, so I am surprised that this code works in 2.7.

Thanks very much,

Robin

RobinL
  • 11,009
  • 8
  • 48
  • 68
  • Can you print your pandas versions for 2.7 and 3? On pandas `'0.12.0-993-gda89834'` 2.7 it raises the exception. – TomAugspurger Nov 24 '13 at 13:31
  • Hello. How do I get the more detailed version number? I've tried pandas.__version__ and all it gives me is 0.12.0 – RobinL Nov 24 '13 at 15:14
  • That's the right way to get the version. Is that what you get for your python 2.7 and 3 pandas? I can't remember when the change was made, but I think it was after the .12 release (the current official release). All the extra stuff after the `0.12.0` is from git since I'm working off the current master. – TomAugspurger Nov 24 '13 at 16:45
  • Thanks. It certainly looks like 0.12.0 on both 2.7 and 3.0. So in future releases it will be immutable? I was using the second answer found here: http://stackoverflow.com/questions/13269890/cartesian-product-in-pandas. It looks like this way of creating a cartesian join will not work in future? – RobinL Nov 24 '13 at 18:27

0 Answers0