Reputation: 2113
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 !
Upvotes: 2
Views: 13458
Reputation: 114911
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)
Upvotes: 5