import pandas as pd
from arcgis.gis import GIS
# Login to AGOL
gis = GIS()
# For other login methods see: https://developers.arcgis.com/python/guide/working-with-different-authentication-schemes/
# use for logging in within active ArcGIS Pro session
# gis = GIS('pro')
# Create a function that returns a list of feature layer collections for a search
def agolSearch(term):
item_list = []
items = gis.content.search(term, item_type="Feature Layer Collection")
for item in items:
item_list.append(item)
return item_list
results = agolSearch('search terms')
results_select = results[0] # select the index postions at which the item you want is positione. This example selects the first result.
# Create dataframe from selected dataset
results_select_df = results_select.layers[0].query().df
# Check out the first 5 records of the new DataFrame
results_select_df.head()