1

I have an example dataframe defined like this in python:

df = pd.DataFrame({
  'col1': ['Item0', 'Item0', 'Item1', 'Item1'],
  'col2': ['Gold', 'Bronze', 'Gold', 'Silver'],
  'col3': [1, 2, np.nan, 4]
   })

when I try to print the dataframe df in jupyter notebook by simply typing df in jupyter and executing it I am getting an error:

TypeError: The numpy boolean negative, the - operator, is not supported, use the ~ operator or the logical_not function instead.

I have tried print(df), converting to html table and printing it, display(df) all are showing the same error.

PS: print(df) or just df were working perfectly fine in jupyter a few weeks back.

5
  • You've probably assigned something incorrect to df what does type(df) show? Also try restarting your kernel as it looks like you have some incorrect state Commented Jun 22, 2017 at 11:21
  • 100% agree with @EdChum. First step is to restart your kernel (or, to be extra safe, jupyter). Second step is to check the type of your df. Commented Jun 22, 2017 at 11:29
  • type(df) shows as : pandas.core.frame.DataFrame Commented Jun 23, 2017 at 4:19
  • and I restarted the kernel still the same error Commented Jun 23, 2017 at 4:21
  • ya even I guess @EdChum is right. I am getting this error only when I run the following program on jupyter running on docker on server. When I executed the same program in the jupyter running on my local machine it works just fine. Commented Jun 23, 2017 at 4:25

4 Answers 4

2

It helped me to upgrade from pandas 0.13 to 0.20.3.

Sign up to request clarification or add additional context in comments.

Comments

1

I just ran into this error in a different setting, and I think the underlying issue is incompatibility with Numpy 1.13, with the (interim) fix being to reinstall with Numpy 1.12.

The change in behavior that's causing the error is that Numpy now throws an error if you try and negate a boolean: https://docs.scipy.org/doc/numpy/release.html#deprecationwarning-to-error

DeprecationWarning to error: negative(bool_), TypeError when negative applied to booleans.

1 Comment

I cannot print(df) or df in Jupyter, or in python. The error msg was: TypeError: reduce() takes at most 5 arguments (6 given). Moving numpy from 1.15 to 1.14 solved it.
1

Try editing the file it gives error. I had a similar issue pointing to file series.py in my python packages at line ~1800 had to manually edit good = -bad to good = ~bad

Surprisingly even when I commented the first line to add the second it game me an error saying - is not supported ...

After editing it manually everything looks fixed.

Comments

-1

Try using iloc,

    df.iloc[0:5] #this will show first 5 rows of the dataframe

for more details visit http://www.shanelynn.ie/select-pandas-dataframe-rows-and-columns-using-iloc-loc-and-ix/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.