Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FutureWarning when unstacking a pandas (v 0.17) dataframe

Tags:

python

pandas

I have recently upgraded to pandas 0.17.0 (numpy: 1.10.1, Python: 2.7.10) and I receive the warning shown in the block below when i try to reshape a dataframe with an unstack operation. The warning appears only the very first time the code is run on a fresh ipython notebook. A rerun on the same notebook does not throw any messages at all for some reason(!!). A similar unstack exists somewhere in the code of a bigger application written with the Pycharm editor. In that case the warning pops out everytime the application is run.

The result of the unstack call looks to be fine, its just the warning that puzzles me and whether it is expected behaviour. Also passing and argument when unstack is called looks to prevent the warning from appearing.

Last note: I was previously using pandas 0.15.2 and the code run smoothly.

Many thanks

In [1]:

import pandas as pd
df = pd.DataFrame([['Maths', 'Student1', 20],['Physics', 'Student2', 21],['Chemistry', 'Student3', 22]], columns=('Subject','Name','Mark'))
df = df.set_index(['Subject','Name'])
df.unstack()

/Users/Name/anaconda/lib/python2.7/site-packages/pandas/core/index.py:
4281: FutureWarning: elementwise comparison failed; returning scalar instead,
but in the future will perform elementwise comparison
  return np.sum(name == np.asarray(self.names)) > 1


Out[1]:
           Mark
Name       Student1  Student2   Student3
Subject         
Chemistry  NaN       NaN        22
Maths      20        NaN        NaN
Physics    NaN       21         NaN
like image 999
Aenaon Avatar asked Nov 04 '15 23:11

Aenaon


1 Answers

This is fixed in master in forthcoming 0.17.1; it doesn't affect anything.

See also the pandas’ github issue tracking this fix for more info.

like image 110
Cimbali Avatar answered Oct 21 '22 10:10

Cimbali