How to solve TypeError: 'numpy.ndarray' object is not callable on Python
13,037
values
is a property of a DataFrame, not a method. Just use d.values
to access the array.
In fact, I think what you want is simply:
ar = d['agency_responsible'].values
or
ar = d.agency_responsible.values
Here's an actual session:
In [1]: import pandas as pd
In [2]: url = "http://311api.cityofchicago.org/open311/v2/requests.json"
In [3]: d = pd.read_json(url)
In [4]: type(d)
Out[4]: pandas.core.frame.DataFrame
In [5]: ar = d.agency_responsible.values
In [6]: ar[0]
Out[6]: u'Bureau of Street Operations - Graffiti'
In [7]: ar[:4]
Out[7]:
array([u'Bureau of Street Operations - Graffiti',
u'Division of Electrical Operations CDOT',
u'Bureau of Rodent Control - S/S',
u'Division of Electrical Operations CDOT'], dtype=object)
Author by
user3001937
Updated on November 25, 2022Comments
-
user3001937 over 1 year
I am working to aggregate Json file in python I use a list comprehension to get all the agency responsibles
import pandas as pd import numpy as np url = "http://311api.cityofchicago.org/open311/v2/requests.json"; d= pd.read_json(url) ar = [x.get("agency_responsible") for x in d.values()]
I got this error :
Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'numpy.ndarray' object is not callable
Then I tried to solve this by adding numpy and dealing with array.
import numpy as np np.[x.get("agency_responsible") for x in d.values()]
But it seems that it doensn't work out !
-
tacaswell over 10 yearsI know that api! Just making sure you are aware of github.com/codeforamerica/srtracker
-
-
user3001937 over 10 yearsHow can we delete the duplicates this way
-
Warren Weckesser over 10 yearsWorks for me--see my updated answer. How to remove duplicates sounds like a new question.
-
user3001937 over 10 yearsYes! 'cause the first methodes has been created to avoid deplicates
-
Warren Weckesser over 10 yearsWhat do you mean by "the first methodes"? I don't see anything in your original question about removing duplicates.
-
user3001937 over 10 yearsnp.[x.get("agency_responsible") for x in d.values()]
-
Warren Weckesser over 10 yearsThat bit of code doesn't work, so I can't guess what you think it is supposed to do. Please edit your question to explain exactly what you are trying to accomplish.