1

Could someone please explain what the following error is about. Following is my code:

import pandas as pd
from pandas import DataFrame
data =pd.read_csv('FILENAME')
b=data.info()
print b

Following is the error:

Traceback (most recent call last):   File  
"FILENAME", line 5, in <module>    
    b=data.info()   File "/usr/lib/python2.7/dist-packages/pandas/core/frame.py", line 1443, in  
info  
    counts = self.count()   File "/usr/lib/python2.7/dist-packages/pandas/core/frame.py", line 3862, in  
count  
    result = notnull(frame).sum(axis=axis)   File "/usr/lib/python2.7/dist-packages/pandas/core/common.py", line 276, in  
notnull  
    return -res   File "/usr/lib/python2.7/dist-packages/pandas/core/generic.py", line 604, in 
__neg__  
arr = operator.neg(_values_from_object(self))
   TypeError: The numpy boolean negative, the `-` operator, is not supported, use the `~`
operator or the logical_not function instead. 

All I am trying to do is display a summary of my dataset using the Dataframe.info() function, and I am having trouble trying to make sense of the error. Although I do feel it has something to do with the numpy package altogether. What needs to be done here?

13
  • P.S:I have started coding in python recently, which is why I am still trying to figure all of this out :-) Commented Sep 11, 2018 at 11:30
  • Does the file FILENAME exist? Commented Sep 11, 2018 at 11:33
  • Yes, it does,i just edited that part out, its a valid file Commented Sep 11, 2018 at 11:35
  • If you want to display the info just call data.info() it won't return anything Commented Sep 11, 2018 at 11:46
  • @SreeramTP that doesn't work either, and besides for displaying it I either need to store the same in a variable or directly use the print statement right? Commented Sep 11, 2018 at 11:50

1 Answer 1

1

The problem is with the old version of pandas as new version of numpy.

You must update pandas to get your code working.

If you are on conda you can do a conda update pandas to update pandas.

If you are using pip you can do pip install --upgrade pandas

Also, keep in mind that in pandas documentation it is mentioned the following for the info function

This method prints information about a DataFrame including the index dtype and column dtypes, non-null values and memory usage

data.info() will print the info to the console. So no need to assign it to a variable and then later printing it.

import pandas as pd
from pandas import DataFrame
data =pd.read_csv('FILENAME')
print data.info()

This code will work fine for you.

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

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.