Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

numpy.ndarray' object is not callable - Using Pandas

I was testing a simple connection from an Amazon Redshift database to my local database using PostgreSQL. I wrote a query to obtain a table from the database, and converted that to a Pandas dataframe. Now, whenever I want to apply some functions on the dataframe objects, I get the following error. I have tried several times to modify it, and looked up a lot of solutions, but can't seem to work around with it.

cur.execute("QUERY for PostgreSQL")
rows = cur.fetchall()
print("Received as rows")
col_names = []
for i in cur.description:
    col_names.append(i[0])
df = pd.DataFrame.from_records(rows, columns = col_names)
df.values()

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-16-8e9714b76ea1> in <module>()
---->  df.values()

TypeError: 'numpy.ndarray' object is not callable
like image 427
Aman Deep Middha Avatar asked Sep 20 '17 08:09

Aman Deep Middha


People also ask

Why is NumPy Ndarray not callable?

This error usually occurs when you attempt to call a NumPy array as a function by using round () brackets instead of square [ ] brackets.

What does DataFrame object is not callable mean?

One common error you may encounter when using pandas is: TypeError: 'DataFrame' object is not callable. This error usually occurs when you attempt to perform some calculation on a variable in a pandas DataFrame by using round () brackets instead of square [ ] brackets.


1 Answers

As @jezael pointed out: df.values is not a function, so you don't need to call it. Just use df.values instead of df.values().

like image 170
MegaIng Avatar answered Sep 21 '22 19:09

MegaIng