Environment:
Windows 10
Python 3.8.5
ArcGIS for Python 1.8.2
Querying ArcGIS Online
The following code works, output as csv, then read that csv back in as a Dataframe:
x = gis.admin.history(start_date=start_date, to_date=end_date, num=100, data_format='csv')
df = pd.read_csv(x)
Leaving everything the same, but trying to output directly as a Dataframe:
df = gis.admin.history(start_date=start_date, to_date=end_date, num=100, data_format='df')
Produces a TypeError :
TypeError: list indices must be integers or slices, not str
Full Traceback:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-69-d921e39fa9da> in <module>
----> 1 df = gis.admin.history(start_date=start_date, to_date=end_date, num=-1, data_format='df')
2 # df = pd.read_csv(x)
~\Anaconda3\lib\site-packages\arcgis\gis\admin\agoladmin.py in history(self, start_date, to_date, num, all_events, event_ids, event_types, actors, owners, actions, ips, sort_order, data_format, save_folder)
338
339 res = self._gis._con.post(url, params)
--> 340 data.extend(data['items'])
341 while len(res['items']) > 0 and res['nextKey']:
342 params['start'] = res['nextKey']
TypeError: list indices must be integers or slices, not str
---------------------------------------------------------------------------
The data variable is a list, so I don’t think we can do this: data['items']
I THINK it’s meant to be: data.extend(res['items']) on line 340 where res is the response from the post (line 339)
res = self._gis._con.post(url, params)
Similarly, on line 345 I changed:
data.extend(data['items']) --> data.extend(res['items'])
Everything seems to be working, but wasn’t sure if my “fix” might break something else? So I was hoping to get some feedback or an “all clear” message that this fix "works" and won't break other things. Thanks!
One quick follow up. This is the change in code I made that seems to work. My version on the left (red highlight) and the original version on the right (green highlight).
*This is in the agoladmin.py file*