<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Exporting results to CSV? in ArcGIS Notebooks Questions</title>
    <link>https://community.esri.com/t5/arcgis-notebooks-questions/exporting-results-to-csv/m-p/1210863#M575</link>
    <description>&lt;P&gt;Hi Dave,&amp;nbsp; thanks for asking this question.&amp;nbsp; Here is one thing you may try.&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. At the top of the script, somewhere above the for loop, add an empty list.&amp;nbsp; Then have the remainder of your script below it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;result = []
for item in my_content:....&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Replace the print statement with the following, and make sure you indent it accordingly after the final if statement:&amp;nbsp; .append should take the print statement and put it into a list, where each line of the print statement (with title, id, type, author) becomes an element of the list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;result.append("{},{},{},{}".format(item.title,item.id,item.type,author))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;3. Then use pandas to convert the list to a dataframe, however at this point the 4 pieces of information will be in one column called "to_split".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;df = pd.DataFrame(result, columns=["to_split"])
df&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;4. You then have to split the column based on the commas, and rename the new columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# split the column based on the comma separators, then rename the new columns
# https://datascienceparichay.com/article/pandas-split-column-by-delimiter/#:~:text=Split%20column%20by%20delimiter%20into,True%20to%20the%20expand%20parameter.

# split column and add new columns to df
df[['item_name', 'item_id', 'item_type', 'author']] = df['to_split'].str.split(',', expand=True)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5. Last, convert it to a CSV file, keeping the columns you want.&amp;nbsp; Because you are using an AGOL notebook, you have to save it to the user workspace.&amp;nbsp; You can then navigate to the files tab and download the CSV locally.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# convert to csv file
df.to_csv("/arcgis/home/test_output_v2.csv", columns=['item_name', 'item_id', 'item_type', 'author'])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="user_workspace.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/50748i31C0F5FC987C832F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="user_workspace.png" alt="user_workspace.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt; Give it a shot and let me know if it works!&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Sep 2022 17:00:48 GMT</pubDate>
    <dc:creator>NicholasGiner1</dc:creator>
    <dc:date>2022-09-08T17:00:48Z</dc:date>
    <item>
      <title>Exporting results to CSV?</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/exporting-results-to-csv/m-p/1198144#M562</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a notebook within AGO that prints all the public facing content within my organization. The results are formatted to be comma delimited to make it easy to import into an excel spreadsheet to share. Is it possible to directly export the results of this script to an excel file?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Script:&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;from arcgis.gis import GIS&lt;BR /&gt;gis = GIS("home")&lt;BR /&gt;from IPython.display import display&lt;/P&gt;&lt;P&gt;my_content = gis.content.search(query="owner:USERNAME",max_items=10000)&lt;BR /&gt;#item_types_need = ['Web Map','Web Mapping Application','StoryMap','Dashboard','Web Experience','Form']&lt;BR /&gt;item_types_need = ['Feature Service']&lt;BR /&gt;for item in my_content:&lt;BR /&gt;if item.type in item_types_need:&lt;BR /&gt;if item.content_status == "public_authoritative":&lt;BR /&gt;author = "Authoritative"&lt;BR /&gt;else:&lt;BR /&gt;author = "None"&lt;BR /&gt;if item.shared_with['everyone']== True:&lt;BR /&gt;print(""'"{}"'",{},{},{}".format(item.title,item.id,item.type,author))&lt;BR /&gt;#display(item)&lt;BR /&gt;print("Completed")&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2022 18:06:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/exporting-results-to-csv/m-p/1198144#M562</guid>
      <dc:creator>DaveK</dc:creator>
      <dc:date>2022-08-01T18:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting results to CSV?</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/exporting-results-to-csv/m-p/1210863#M575</link>
      <description>&lt;P&gt;Hi Dave,&amp;nbsp; thanks for asking this question.&amp;nbsp; Here is one thing you may try.&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. At the top of the script, somewhere above the for loop, add an empty list.&amp;nbsp; Then have the remainder of your script below it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;result = []
for item in my_content:....&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Replace the print statement with the following, and make sure you indent it accordingly after the final if statement:&amp;nbsp; .append should take the print statement and put it into a list, where each line of the print statement (with title, id, type, author) becomes an element of the list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;result.append("{},{},{},{}".format(item.title,item.id,item.type,author))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;3. Then use pandas to convert the list to a dataframe, however at this point the 4 pieces of information will be in one column called "to_split".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;df = pd.DataFrame(result, columns=["to_split"])
df&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;4. You then have to split the column based on the commas, and rename the new columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# split the column based on the comma separators, then rename the new columns
# https://datascienceparichay.com/article/pandas-split-column-by-delimiter/#:~:text=Split%20column%20by%20delimiter%20into,True%20to%20the%20expand%20parameter.

# split column and add new columns to df
df[['item_name', 'item_id', 'item_type', 'author']] = df['to_split'].str.split(',', expand=True)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5. Last, convert it to a CSV file, keeping the columns you want.&amp;nbsp; Because you are using an AGOL notebook, you have to save it to the user workspace.&amp;nbsp; You can then navigate to the files tab and download the CSV locally.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# convert to csv file
df.to_csv("/arcgis/home/test_output_v2.csv", columns=['item_name', 'item_id', 'item_type', 'author'])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="user_workspace.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/50748i31C0F5FC987C832F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="user_workspace.png" alt="user_workspace.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt; Give it a shot and let me know if it works!&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 17:00:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/exporting-results-to-csv/m-p/1210863#M575</guid>
      <dc:creator>NicholasGiner1</dc:creator>
      <dc:date>2022-09-08T17:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting results to CSV?</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/exporting-results-to-csv/m-p/1559298#M856</link>
      <description>&lt;P&gt;Hello Nicholas,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've done precisely what you suggested here.&amp;nbsp; I am able to create the CSV file...but when running the tool inside a map viewer I am getting an error that suggests the file/folder does not exist or I don't have permissions to the folder.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Notebook_tool_error.jpg" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/119681i8BA8B26285CDB4CD/image-size/large?v=v2&amp;amp;px=999" role="button" title="Notebook_tool_error.jpg" alt="Notebook_tool_error.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 18:18:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/exporting-results-to-csv/m-p/1559298#M856</guid>
      <dc:creator>Alex_Rodriguez</dc:creator>
      <dc:date>2024-11-15T18:18:26Z</dc:date>
    </item>
  </channel>
</rss>

