{"id":1163122,"date":"2021-03-23T08:32:27","date_gmt":"2021-03-23T15:32:27","guid":{"rendered":"https:\/\/www.esri.com\/arcgis-blog\/?post_type=blog&#038;p=1163122"},"modified":"2021-03-24T14:07:19","modified_gmt":"2021-03-24T21:07:19","slug":"a-primer-for-python-scripting-in-insights","status":"publish","type":"blog","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights","title":{"rendered":"A Primer for Python Scripting in ArcGIS Insights"},"author":203542,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"_acf_changed":false,"_searchwp_excluded":""},"categories":[23341],"tags":[23551,26221,24341,23391,27911],"industry":[],"product":[36801],"class_list":["post-1163122","blog","type-blog","status-publish","format-standard","hentry","category-analytics","tag-location-analytics","tag-open-data","tag-python","tag-spatial-analytics","tag-tutorial","product-insights"],"acf":{"short_description":"Get started with scripting in ArcGIS Insights by learning about our scripting logic and data wrangling workflows in a hands-on example.","flexible_content":[{"acf_fc_layout":"content","content":"<p><em>This hands-on blog post, you will learn about the scripting logic and common data workflows that will allow you to get the most out of Python scripting in Insights. You are not a Python user? Fret not! While we will wrangle data using Python in the second half of this post, many of the concepts discussed here can be applied to R as well.<\/em><\/p>\n<h2><strong>Interacting with scripts<\/strong><\/h2>\n<p>Let\u2019s get to it! Before we dive into our hands-on example, let\u2019s have a look at logic of <em>creating<\/em> and <em>running<\/em> scripts in Insights. We will also touch upon certain aspects of the user interface. If you want to familiarize yourself with the entire user interface, check out the official <a href=\"https:\/\/doc.arcgis.com\/en\/insights\/latest\/analyze\/use-scripting-console.htm\">Insights documentation<\/a>.<\/p>\n<h3>Creating scripts<\/h3>\n<p>There are two ways to create scripts in Insights:<\/p>\n<p><strong>Creating a new script by opening the scripting environment console<\/strong>: After you selected a Python or R Kernel in the console, Insights will automatically populate the data pane with a script element.<\/p>\n<p><strong>Creating a new script from an existing script:<\/strong> The <code>add to model<\/code> button in the console toolbar of your existing scripts allows you to create a new script from the selected cell. By doing so, the newly created script gets added to the Insights <a href=\"https:\/\/doc.arcgis.com\/en\/insights\/latest\/share\/share-model.htm\">model<\/a>. Adding a script to a model is a helpful way to rerun your workflow with different data.<\/p>\n<p>Generally, I recommend limiting the number of independent scripts in your workbook. Insight\u2019s scripting capability is not optimized for many scripts: Each time you open an existing script, the previous <a href=\"https:\/\/jupyter-client.readthedocs.io\/en\/stable\/kernels.html#:~:text=A%20'kernel'%20is%20a%20program,the%20kernel%20a%20connection%20file.&amp;text=You%20can%20implement%20the%20kernel%20machinery%20in%20your%20target%20language.\">Kernel<\/a> is destroyed and a new one is created. You can reduce scripts by adding multiple functions to one script or by breaking up your code into logical blocks using code cells.<\/p>\n<h3>Running scripts<\/h3>\n<p>Once you have added your script to Insights and written some code, you have three options to run your script. Each of them serves a different purpose:<\/p>\n<p><strong>Running in console:<\/strong> Click on the <code>Run<\/code> button in the scripting environment toolbar. I recommend this method for debugging purposes or if you created a custom Python visualization that you would like to add to your workbook.<\/p>\n<p>&nbsp;<\/p>\n"},{"acf_fc_layout":"image","image":{"ID":1168582,"id":1168582,"title":"run21","filename":"run21.jpg","filesize":55052,"url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run21.jpg","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights\/run21","alt":"Running script in console","author":"203542","description":"Running script in console","caption":"Running script in console","name":"run21","status":"inherit","uploaded_to":1163122,"date":"2021-03-22 23:47:22","modified":"2021-03-22 23:56:01","menu_order":0,"mime_type":"image\/jpeg","type":"image","subtype":"jpeg","icon":"https:\/\/www.esri.com\/arcgis-blog\/wp-includes\/images\/media\/default.png","width":1435,"height":835,"sizes":{"thumbnail":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run21-213x200.jpg","thumbnail-width":213,"thumbnail-height":200,"medium":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run21.jpg","medium-width":449,"medium-height":261,"medium_large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run21.jpg","medium_large-width":768,"medium_large-height":447,"large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run21.jpg","large-width":1435,"large-height":835,"1536x1536":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run21.jpg","1536x1536-width":1435,"1536x1536-height":835,"2048x2048":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run21.jpg","2048x2048-width":1435,"2048x2048-height":835,"card_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run21-799x465.jpg","card_image-width":799,"card_image-height":465,"wide_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run21.jpg","wide_image-width":1435,"wide_image-height":835}},"image_position":"center","orientation":"horizontal","hyperlink":""},{"acf_fc_layout":"content","content":"<p><strong>Running from model:<\/strong> In order to run from model, you need to add your script to the model first. In addition, you need to pull in data from Insights into your script (more on this in the second half). Switching to analysis view and clicking on the <code>edit<\/code> icon will prompt you to replace and rerun the script with new fields. Note: Make sure you rerun your script with valid fields as defined by your script. Otherwise, the script will fail.<\/p>\n<p>&nbsp;<\/p>\n"},{"acf_fc_layout":"image","image":{"ID":1168592,"id":1168592,"title":"run31","filename":"run31-1.jpg","filesize":57673,"url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run31-1.jpg","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights\/run31-2","alt":"Running script from model","author":"203542","description":"Running script from model","caption":"Running script from model","name":"run31-2","status":"inherit","uploaded_to":1163122,"date":"2021-03-22 23:47:59","modified":"2021-03-22 23:56:23","menu_order":0,"mime_type":"image\/jpeg","type":"image","subtype":"jpeg","icon":"https:\/\/www.esri.com\/arcgis-blog\/wp-includes\/images\/media\/default.png","width":1435,"height":835,"sizes":{"thumbnail":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run31-1-213x200.jpg","thumbnail-width":213,"thumbnail-height":200,"medium":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run31-1.jpg","medium-width":449,"medium-height":261,"medium_large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run31-1.jpg","medium_large-width":768,"medium_large-height":447,"large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run31-1.jpg","large-width":1435,"large-height":835,"1536x1536":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run31-1.jpg","1536x1536-width":1435,"1536x1536-height":835,"2048x2048":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run31-1.jpg","2048x2048-width":1435,"2048x2048-height":835,"card_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run31-1-799x465.jpg","card_image-width":799,"card_image-height":465,"wide_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run31-1.jpg","wide_image-width":1435,"wide_image-height":835}},"image_position":"center","orientation":"horizontal","hyperlink":""},{"acf_fc_layout":"content","content":"<p><strong>Running from Insights data pane<\/strong>: You can run a script from the data pane by clicking on the three dots to the right of it and selecting <code>run<\/code>. This will run any script, no matter if it is pulling in data from Insights or not. This is useful if you made a change to your script and want to rerun it without replacing any field names.<\/p>\n"},{"acf_fc_layout":"image","image":{"ID":1168652,"id":1168652,"title":"run11","filename":"run11.jpg","filesize":40012,"url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run11.jpg","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights\/run11","alt":"Running script from data pane","author":"203542","description":"Running script from data pane","caption":"Running script from data pane","name":"run11","status":"inherit","uploaded_to":1163122,"date":"2021-03-22 23:54:40","modified":"2021-03-22 23:56:41","menu_order":0,"mime_type":"image\/jpeg","type":"image","subtype":"jpeg","icon":"https:\/\/www.esri.com\/arcgis-blog\/wp-includes\/images\/media\/default.png","width":1435,"height":835,"sizes":{"thumbnail":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run11-213x200.jpg","thumbnail-width":213,"thumbnail-height":200,"medium":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run11.jpg","medium-width":449,"medium-height":261,"medium_large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run11.jpg","medium_large-width":768,"medium_large-height":447,"large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run11.jpg","large-width":1435,"large-height":835,"1536x1536":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run11.jpg","1536x1536-width":1435,"1536x1536-height":835,"2048x2048":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run11.jpg","2048x2048-width":1435,"2048x2048-height":835,"card_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run11-799x465.jpg","card_image-width":799,"card_image-height":465,"wide_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/run11.jpg","wide_image-width":1435,"wide_image-height":835}},"image_position":"center","orientation":"horizontal","hyperlink":""},{"acf_fc_layout":"content","content":"<h2><strong>Working with scripts: One example, three workflows<\/strong><\/h2>\n<p>Now that we know more about scripting logic, let\u2019s dive into how we can combine scripting with Insights\u2019 core functionalities. I will walk you through three different data wrangling workflows using one example for all three workflows. In the example, we want to find out if there is a spatial correlation between median household incomes of Census tracts in New York City.<\/p>\n<h3>Before we get started<\/h3>\n<p>We will talk about the general concepts of integrating scripting in Insights and won\u2019t discuss every single line of code. If you would like to see what each line of code is doing, this is what you need to follow along:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/Esri\/insights-scripting-guide\/tree\/master\/Py\/primer\">Github repo<\/a> containing required shapefile and code snippets<\/li>\n<li><a href=\"https:\/\/www.census.gov\/data\/developers\/guidance\/api-user-guide.html\">Census API Key<\/a><\/li>\n<li>Kernel gateway to an environment with the required Python dependencies (Documentation on how to setup a Kernel gateway <a href=\"https:\/\/github.com\/Esri\/insights-scripting-guide\">here<\/a> and list of dependencies <a href=\"https:\/\/github.com\/Esri\/insights-scripting-guide\/blob\/master\/Py\/primer\/environment.yml\">here<\/a>).<\/li>\n<li>Basic understanding of dataframe structures in <a href=\"https:\/\/pandas.pydata.org\/\">Pandas<\/a> and <a href=\"https:\/\/geopandas.org\/\">Geopandas<\/a><\/li>\n<\/ul>\n<h3>Workflow one: Querying external data<\/h3>\n<p>One powerful scripting workflow is to fetch external data from REST APIs or <a href=\"https:\/\/github.com\/Esri\/insights-scripting-guide\/tree\/master\/Py\/database_connections\">databases<\/a> and return it to Insights. This is helpful if your data frequently changes. Instead of updating your own datasource, you can simply rerun the script and pull the updated data. Today, we will use the popular <a href=\"https:\/\/requests.readthedocs.io\/en\/master\/\">Requests<\/a> library for Python to fetch median household income data through the Census API. After that, we will format the fetched data using <a href=\"https:\/\/pandas.pydata.org\/\">Pandas<\/a>. To do so, let&#8217;s create a new Python script in Insights, rename it to <code>rest_api<\/code> and import the script from <a href=\"https:\/\/github.com\/Esri\/insights-scripting-guide\/blob\/master\/Py\/primer\/rest_api.py\">here<\/a>. Don&#8217;t run it yet, we will need to make some changes to the API key first.<\/p>\n<p>&nbsp;<\/p>\n"},{"acf_fc_layout":"image","image":{"ID":1168702,"id":1168702,"title":"requests2","filename":"requests2.png","filesize":63502,"url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/requests2.png","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights\/requests2","alt":"Making a call to the Census API","author":"203542","description":"Making a call to the Census API","caption":"Making a call to the Census API","name":"requests2","status":"inherit","uploaded_to":1163122,"date":"2021-03-23 00:06:08","modified":"2021-03-23 00:13:18","menu_order":0,"mime_type":"image\/png","type":"image","subtype":"png","icon":"https:\/\/www.esri.com\/arcgis-blog\/wp-includes\/images\/media\/default.png","width":1014,"height":344,"sizes":{"thumbnail":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/requests2-213x200.png","thumbnail-width":213,"thumbnail-height":200,"medium":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/requests2.png","medium-width":464,"medium-height":157,"medium_large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/requests2.png","medium_large-width":768,"medium_large-height":261,"large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/requests2.png","large-width":1014,"large-height":344,"1536x1536":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/requests2.png","1536x1536-width":1014,"1536x1536-height":344,"2048x2048":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/requests2.png","2048x2048-width":1014,"2048x2048-height":344,"card_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/requests2-826x280.png","card_image-width":826,"card_image-height":280,"wide_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/requests2.png","wide_image-width":1014,"wide_image-height":344}},"image_position":"center","orientation":"horizontal","hyperlink":""},{"acf_fc_layout":"content","content":"<p>If you are following along, take a minute to examine the code to understand how the API call works. After transforming the API response to a Pandas dataframe and doing some reformatting, we will employ Insights\u2019 magic function to return the dataframe to Insights:<\/p>\n<p><code>%insights_return(df)<\/code><code><\/code><\/p>\n<p>Running the above code will output your dataframe <code>df<\/code> as a new dataset called <code>layer<\/code> to the Insights data pane. It is good practice to rename the resulting dataset. Here, we\u2019ll rename <code>layer<\/code> to <code>census_data_api<\/code>. Note that there are some limitations to the magic function: It is currently only possible to return Pandas dataframes (no geodataframes or other data formats).<\/p>\n<h3>Workflow two: Reading local files<\/h3>\n<p>As you might have noticed, the above script imports a script named <code>config<\/code> on line 1. This is an example of workflow two: storing files locally. You could employ this workflow when you have API keys that you do not want to expose in your workbook. In our example, we created <a href=\"https:\/\/github.com\/Esri\/insights-scripting-guide\/blob\/master\/Py\/primer\/config.py\">another script<\/a> named <code>config.py<\/code> containing a single variable with the API key needed to access our API endpoint:<\/p>\n<p><code>apptoken = &lt;myapikey&gt;<\/code><\/p>\n"},{"acf_fc_layout":"content","content":"<p>You need to move this file into a directory named <code>data<\/code> on the machine where your Kernel gateway is running. The <code>data<\/code> directory is part of the Kernel gateway directory (It is possible that you have to create the <code>data<\/code> directory first). From <code>data<\/code>, your Insights script will be able to access files without you having to specify paths. \u00a0Now, you should be able to run the above script with your own API key!<\/p>\n<h3>Workflow three: Adding datasets to the Insights console<\/h3>\n<p>While the above tools are very practical for remote data fetching, let\u2019s walk through at a slightly more involved workflow. Insights comes with many common analysis methods already built-in. But sometimes, you might need a specific statistical method that you cannot find in the core toolkit. Luckily, you can use any library that you can think of with the power of Insights scripting!<\/p>\n<p>Let\u2019s return to our example to demonstrate the last workflow: As mentioned in the beginning, we want to know if there is any spatial correlation between median household incomes of Census tracts in New York City. One way to measure spatial correlation is a statistical method called <a href=\"https:\/\/desktop.arcgis.com\/en\/arcmap\/10.3\/tools\/spatial-statistics-toolbox\/h-how-spatial-autocorrelation-moran-s-i-spatial-st.htm\">Moran\u2019s I<\/a>. Without going into too much detail, Moran\u2019s I is a number that indicates the amount of correlation between spatial features. It is not part of Insight\u2019s core toolkit, but thanks to our scripting interface we can easily run it in Insights. In our case, the spatial features are Census tract polygons.<\/p>\n<p>Before we can calculate Moran&#8217;s I on them, we need to join our <code>census_data_api<\/code> data to the polygons. Import the <a href=\"https:\/\/github.com\/Esri\/insights-scripting-guide\/blob\/master\/Py\/primer\/census_tracts_poly.zip\">Census tract shapefile<\/a> into to your workbook and click on the relationship icon in the top left corner. Drag in both datasets into the pane to perform an inner join on the fields <code>COUNTY<\/code> and <code>TRACT<\/code> as seen below:<\/p>\n"},{"acf_fc_layout":"image","image":{"ID":1168042,"id":1168042,"title":"join_data4","filename":"join_data4.jpg","filesize":46492,"url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/join_data4.jpg","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights\/join_data4","alt":"Joining API data to polygons","author":"203542","description":"Joining API data to polygons","caption":"Joining API data to polygons","name":"join_data4","status":"inherit","uploaded_to":1163122,"date":"2021-03-22 20:12:16","modified":"2021-03-22 23:57:14","menu_order":0,"mime_type":"image\/jpeg","type":"image","subtype":"jpeg","icon":"https:\/\/www.esri.com\/arcgis-blog\/wp-includes\/images\/media\/default.png","width":1530,"height":842,"sizes":{"thumbnail":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/join_data4-213x200.jpg","thumbnail-width":213,"thumbnail-height":200,"medium":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/join_data4.jpg","medium-width":464,"medium-height":255,"medium_large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/join_data4.jpg","medium_large-width":768,"medium_large-height":423,"large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/join_data4.jpg","large-width":1530,"large-height":842,"1536x1536":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/join_data4.jpg","1536x1536-width":1530,"1536x1536-height":842,"2048x2048":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/join_data4.jpg","2048x2048-width":1530,"2048x2048-height":842,"card_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/join_data4-826x455.jpg","card_image-width":826,"card_image-height":455,"wide_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/join_data4.jpg","wide_image-width":1530,"wide_image-height":842}},"image_position":"center","orientation":"horizontal","hyperlink":""},{"acf_fc_layout":"content","content":"<p>You should end up with a joined dataset. Now, we are ready to make use of another magical Insights trick. First, create a new Python script from console and import the <code>morans_i.py<\/code> script from the <a href=\"https:\/\/github.com\/Esri\/insights-scripting-guide\/tree\/master\/Py\/primer\">repo<\/a>. From the joined dataset, drag and drop the fields <code>census_tracts_2018_poly<\/code> , <code>tract<\/code> and the field for income, <code>B19013_001E<\/code>, into your scripting console. In your script, assign them to the variable <code>gdf<\/code> on line 6. The output should look like this:<\/p>\n"},{"acf_fc_layout":"image","image":{"ID":1168072,"id":1168072,"title":"dnd_data","filename":"dnd_data.jpg","filesize":94070,"url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/dnd_data.jpg","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights\/dnd_data","alt":"Moran's I script","author":"203542","description":"Moran's I script","caption":"Moran's I script","name":"dnd_data","status":"inherit","uploaded_to":1163122,"date":"2021-03-22 20:19:54","modified":"2021-03-22 23:57:33","menu_order":0,"mime_type":"image\/jpeg","type":"image","subtype":"jpeg","icon":"https:\/\/www.esri.com\/arcgis-blog\/wp-includes\/images\/media\/default.png","width":1263,"height":686,"sizes":{"thumbnail":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/dnd_data-213x200.jpg","thumbnail-width":213,"thumbnail-height":200,"medium":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/dnd_data.jpg","medium-width":464,"medium-height":252,"medium_large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/dnd_data.jpg","medium_large-width":768,"medium_large-height":417,"large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/dnd_data.jpg","large-width":1263,"large-height":686,"1536x1536":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/dnd_data.jpg","1536x1536-width":1263,"1536x1536-height":686,"2048x2048":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/dnd_data.jpg","2048x2048-width":1263,"2048x2048-height":686,"card_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/dnd_data-826x449.jpg","card_image-width":826,"card_image-height":449,"wide_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/dnd_data.jpg","wide_image-width":1263,"wide_image-height":686}},"image_position":"center","orientation":"horizontal","hyperlink":""},{"acf_fc_layout":"content","content":"<p>You just created your first geodataframe from an Insights dataset! To verify that this is actually the case, add the code below. It should output <em>geodataframe<\/em> as type.<\/p>\n<p><code>type(df)<\/code><\/p>\n<p>So what just happened? This behavior is particular to Insights scripting: because it has the Python libraries Pandas, Geopandas, Requests and Numpy baked in, it automatically transforms your fields into dataframes or geodataframes (the latter if your data contains a location field). Similarly, if you want to run other Pandas or Geopandas tools, there is no need to specifically import these libraries. Simply run your tools and append <code>pd<\/code>, <code>gpd<\/code> or <code>np<\/code> as needed.<\/p>\n<p>Now that we have access in our script to the fields required, we are ready to run our script to calculate Moran\u2019s I. We\u2019ll leverage the open-source Python libraries <a href=\"https:\/\/pysal.org\/libpysal\/\">libpysal<\/a> and <a href=\"https:\/\/pysal.org\/esda\/\">esda<\/a>, which contain all the tools we need. Since they are not part of the Insights scripting setup, these libraries will have to be imported the standard Python way, e.g. by using <code>from libpysal.weights import Queen<\/code>. Have a look at the entire code before you hit <code>run<\/code>!<\/p>\n<p>&nbsp;<\/p>\n"},{"acf_fc_layout":"content","content":"<h3>Workflow results<\/h3>\n<p>If all went well, you should see a new dataset called <code>layer<\/code> populate your Insights data pane. Click on the three dots to the right of it and select <code>View data table<\/code>. You should see two rows, <code>Moran\u2019s I<\/code> and <code>p-value<\/code>. We can use this dataset to create a summary table card in the workbook. Congratulations, you made it!<\/p>\n"},{"acf_fc_layout":"image","image":{"ID":1167432,"id":1167432,"title":"Summary table containing Moran's I and p-value","filename":"Screen-Shot-2021-03-22-at-9.01.52-AM.png","filesize":6737,"url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/Screen-Shot-2021-03-22-at-9.01.52-AM.png","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights\/screen-shot-2021-03-22-at-9-01-52-am","alt":"Summary table Moran's I","author":"203542","description":"Summary table containing Moran's I and p-value","caption":"Summary table containing Moran's I and p-value","name":"screen-shot-2021-03-22-at-9-01-52-am","status":"inherit","uploaded_to":1163122,"date":"2021-03-22 13:02:45","modified":"2021-03-22 13:31:51","menu_order":0,"mime_type":"image\/png","type":"image","subtype":"png","icon":"https:\/\/www.esri.com\/arcgis-blog\/wp-includes\/images\/media\/default.png","width":620,"height":172,"sizes":{"thumbnail":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/Screen-Shot-2021-03-22-at-9.01.52-AM-213x172.png","thumbnail-width":213,"thumbnail-height":172,"medium":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/Screen-Shot-2021-03-22-at-9.01.52-AM.png","medium-width":464,"medium-height":129,"medium_large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/Screen-Shot-2021-03-22-at-9.01.52-AM.png","medium_large-width":620,"medium_large-height":172,"large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/Screen-Shot-2021-03-22-at-9.01.52-AM.png","large-width":620,"large-height":172,"1536x1536":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/Screen-Shot-2021-03-22-at-9.01.52-AM.png","1536x1536-width":620,"1536x1536-height":172,"2048x2048":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/Screen-Shot-2021-03-22-at-9.01.52-AM.png","2048x2048-width":620,"2048x2048-height":172,"card_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/Screen-Shot-2021-03-22-at-9.01.52-AM.png","card_image-width":620,"card_image-height":172,"wide_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/Screen-Shot-2021-03-22-at-9.01.52-AM.png","wide_image-width":620,"wide_image-height":172}},"image_position":"center","orientation":"horizontal","hyperlink":""},{"acf_fc_layout":"content","content":"<h2><strong>Summary<\/strong><\/h2>\n<p>Let\u2019s rehash the three workflows described above in a more general manner. In <strong>workflow one<\/strong>, we looked at a way of using Python scripting to pull in external data, do processing in Python and bring it into Insights for further transformation using <code>%insights_return(&lt;dataframe&gt;)<\/code>.<\/p>\n"},{"acf_fc_layout":"image","image":{"ID":1167642,"id":1167642,"title":"workflow1","filename":"workflow1.jpg","filesize":20104,"url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow1.jpg","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights\/workflow1","alt":"Workflow one","author":"203542","description":"Workflow one","caption":"Workflow one","name":"workflow1","status":"inherit","uploaded_to":1163122,"date":"2021-03-22 14:14:31","modified":"2021-03-22 14:14:43","menu_order":0,"mime_type":"image\/jpeg","type":"image","subtype":"jpeg","icon":"https:\/\/www.esri.com\/arcgis-blog\/wp-includes\/images\/media\/default.png","width":1318,"height":136,"sizes":{"thumbnail":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow1-213x136.jpg","thumbnail-width":213,"thumbnail-height":136,"medium":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow1.jpg","medium-width":464,"medium-height":48,"medium_large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow1.jpg","medium_large-width":768,"medium_large-height":79,"large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow1.jpg","large-width":1318,"large-height":136,"1536x1536":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow1.jpg","1536x1536-width":1318,"1536x1536-height":136,"2048x2048":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow1.jpg","2048x2048-width":1318,"2048x2048-height":136,"card_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow1-826x85.jpg","card_image-width":826,"card_image-height":85,"wide_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow1.jpg","wide_image-width":1318,"wide_image-height":136}},"image_position":"center","orientation":"horizontal","hyperlink":""},{"acf_fc_layout":"content","content":"<p>In <strong>workflow two<\/strong>, we imported a local script located in the <code>gateway\/data<\/code> directory on your server machine to pull in information like API keys without having to expose the data in the workbook itself.<\/p>\n"},{"acf_fc_layout":"image","image":{"ID":1167672,"id":1167672,"title":"workflow21","filename":"workflow21.jpg","filesize":11818,"url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow21.jpg","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights\/workflow21","alt":"Workflow two","author":"203542","description":"Workflow two","caption":"Workflow two","name":"workflow21","status":"inherit","uploaded_to":1163122,"date":"2021-03-22 14:23:30","modified":"2021-03-22 14:23:42","menu_order":0,"mime_type":"image\/jpeg","type":"image","subtype":"jpeg","icon":"https:\/\/www.esri.com\/arcgis-blog\/wp-includes\/images\/media\/default.png","width":1323,"height":126,"sizes":{"thumbnail":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow21-213x126.jpg","thumbnail-width":213,"thumbnail-height":126,"medium":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow21.jpg","medium-width":464,"medium-height":44,"medium_large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow21.jpg","medium_large-width":768,"medium_large-height":73,"large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow21.jpg","large-width":1323,"large-height":126,"1536x1536":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow21.jpg","1536x1536-width":1323,"1536x1536-height":126,"2048x2048":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow21.jpg","2048x2048-width":1323,"2048x2048-height":126,"card_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow21-826x79.jpg","card_image-width":826,"card_image-height":79,"wide_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow21.jpg","wide_image-width":1323,"wide_image-height":126}},"image_position":"center","orientation":"horizontal","hyperlink":""},{"acf_fc_layout":"content","content":"<p><strong>Workflow three<\/strong> demonstrated how you can use the drag and drop mechanism to pull in Insights datasets and how they automatically get converted to dataframes or geodataframes. This allows you to run custom Python scripts against Insights data.<\/p>\n"},{"acf_fc_layout":"image","image":{"ID":1167682,"id":1167682,"title":"workflow31","filename":"workflow31.jpg","filesize":16843,"url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow31.jpg","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights\/workflow31","alt":"Workflow three","author":"203542","description":"Workflow three","caption":"Workflow three","name":"workflow31","status":"inherit","uploaded_to":1163122,"date":"2021-03-22 14:23:55","modified":"2021-03-22 14:24:11","menu_order":0,"mime_type":"image\/jpeg","type":"image","subtype":"jpeg","icon":"https:\/\/www.esri.com\/arcgis-blog\/wp-includes\/images\/media\/default.png","width":1323,"height":128,"sizes":{"thumbnail":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow31-213x128.jpg","thumbnail-width":213,"thumbnail-height":128,"medium":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow31.jpg","medium-width":464,"medium-height":45,"medium_large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow31.jpg","medium_large-width":768,"medium_large-height":74,"large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow31.jpg","large-width":1323,"large-height":128,"1536x1536":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow31.jpg","1536x1536-width":1323,"1536x1536-height":128,"2048x2048":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow31.jpg","2048x2048-width":1323,"2048x2048-height":128,"card_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow31-826x80.jpg","card_image-width":826,"card_image-height":80,"wide_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/workflow31.jpg","wide_image-width":1323,"wide_image-height":128}},"image_position":"center","orientation":"horizontal","hyperlink":""},{"acf_fc_layout":"content","content":"<h2><strong>What&#8217;s next<\/strong><\/h2>\n<p>That\u2019s it for today! If you found this blog helpful, check out our other ArcGIS Insights scripting resources: Learn how to <a href=\"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/mapping\/make-this-watershed-workbook-chart-vision\/\">conduct a watershed analysis with Python<\/a>, check out <a href=\"https:\/\/www.esri.com\/arcgis-blog\/?s=#&amp;products=insights&amp;page=2\">this blog about Apache Spark and Insights<\/a> or have a look at our Insights scripting documentation.<\/p>\n"}],"authors":[{"ID":203542,"user_firstname":"Melanie","user_lastname":"Imfeld","nickname":"mimfeld","user_nicename":"mimfeld","display_name":"Melanie Imfeld","user_email":"mimfeld@esri.com","user_url":"","user_registered":"2021-03-16 16:12:13","user_description":"Melanie is part of the ArcGIS Insights team and a maps and data visualization enthusiast. Originally from Switzerland, she spent multiple years in Europe working in the area of business intelligence and data driven urban design. Growing up nearby mountains, she is a keen hiker and outdoor lover.","user_avatar":"<img data-del=\"avatar\" src='https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/image-213x200.jpg' class='avatar pp-user-avatar avatar-96 photo ' height='96' width='96'\/>"}],"related_articles":[{"ID":1085501,"post_author":"129801","post_date":"2020-12-14 10:13:46","post_date_gmt":"2020-12-14 18:13:46","post_content":"","post_title":"Make this Watershed Workbook: Some Assembly Required","post_excerpt":"","post_status":"publish","comment_status":"open","ping_status":"closed","post_password":"","post_name":"make-this-watershed-workbook-data-prep","to_ping":"","pinged":"","post_modified":"2021-07-08 16:57:24","post_modified_gmt":"2021-07-08 23:57:24","post_content_filtered":"","post_parent":0,"guid":"https:\/\/www.esri.com\/arcgis-blog\/?post_type=blog&#038;p=1085501","menu_order":0,"post_type":"blog","post_mime_type":"","comment_count":"0","filter":"raw"},{"ID":967941,"post_author":"61811","post_date":"2020-08-06 14:49:43","post_date_gmt":"2020-08-06 21:49:43","post_content":"","post_title":"Business Intelligence at Scale: Leveraging Apache Spark within ArcGIS Insights","post_excerpt":"","post_status":"publish","comment_status":"open","ping_status":"closed","post_password":"","post_name":"business-intelligence-at-scale-leveraging-apache-spark-within-arcgis-insights","to_ping":"","pinged":"","post_modified":"2020-08-06 15:00:00","post_modified_gmt":"2020-08-06 22:00:00","post_content_filtered":"","post_parent":0,"guid":"https:\/\/www.esri.com\/arcgis-blog\/?post_type=blog&#038;p=967941","menu_order":0,"post_type":"blog","post_mime_type":"","comment_count":"1","filter":"raw"},{"ID":488312,"post_author":"7711","post_date":"2019-04-18 14:50:06","post_date_gmt":"2019-04-18 21:50:06","post_content":"","post_title":"Scripting in Insights for ArcGIS","post_excerpt":"","post_status":"publish","comment_status":"closed","ping_status":"closed","post_password":"","post_name":"scripting-insights-arcgis","to_ping":"","pinged":"","post_modified":"2019-04-18 14:57:05","post_modified_gmt":"2019-04-18 21:57:05","post_content_filtered":"","post_parent":0,"guid":"https:\/\/www.esri.com\/arcgis-blog\/?post_type=blog&#038;p=488312","menu_order":0,"post_type":"blog","post_mime_type":"","comment_count":"0","filter":"raw"}],"card_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/card.jpg","wide_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/header_new_2.jpg"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>A Primer for Python Scripting in ArcGIS Insights<\/title>\n<meta name=\"description\" content=\"Get started with scripting in ArcGIS Insights by learning about our scripting logic and data wrangling workflows\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A Primer for Python Scripting in ArcGIS Insights\" \/>\n<meta property=\"og:description\" content=\"Get started with scripting in ArcGIS Insights by learning about our scripting logic and data wrangling workflows\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights\" \/>\n<meta property=\"og:site_name\" content=\"ArcGIS Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/esrigis\/\" \/>\n<meta property=\"article:modified_time\" content=\"2021-03-24T21:07:19+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@ESRI\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights\"},\"author\":{\"name\":\"Melanie Imfeld\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/c2317c27946a6759eee525497d63901e\"},\"headline\":\"A Primer for Python Scripting in ArcGIS Insights\",\"datePublished\":\"2021-03-23T15:32:27+00:00\",\"dateModified\":\"2021-03-24T21:07:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights\"},\"wordCount\":8,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#organization\"},\"keywords\":[\"location analytics\",\"open data\",\"python\",\"spatial analytics\",\"Tutorial\"],\"articleSection\":[\"Analytics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights\",\"name\":\"A Primer for Python Scripting in ArcGIS Insights\",\"isPartOf\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#website\"},\"datePublished\":\"2021-03-23T15:32:27+00:00\",\"dateModified\":\"2021-03-24T21:07:19+00:00\",\"description\":\"Get started with scripting in ArcGIS Insights by learning about our scripting logic and data wrangling workflows\",\"breadcrumb\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.esri.com\/arcgis-blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"A Primer for Python Scripting in ArcGIS Insights\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#website\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/\",\"name\":\"ArcGIS Blog\",\"description\":\"Get insider info from Esri product teams\",\"publisher\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.esri.com\/arcgis-blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#organization\",\"name\":\"Esri\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/Esri.png\",\"contentUrl\":\"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/Esri.png\",\"width\":400,\"height\":400,\"caption\":\"Esri\"},\"image\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/esrigis\/\",\"https:\/\/x.com\/ESRI\",\"https:\/\/www.linkedin.com\/company\/5311\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/c2317c27946a6759eee525497d63901e\",\"name\":\"Melanie Imfeld\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/image-213x200.jpg\",\"contentUrl\":\"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/image-213x200.jpg\",\"caption\":\"Melanie Imfeld\"},\"description\":\"Melanie is part of the ArcGIS Insights team and a maps and data visualization enthusiast. Originally from Switzerland, she spent multiple years in Europe working in the area of business intelligence and data driven urban design. Growing up nearby mountains, she is a keen hiker and outdoor lover.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/melanie-imfeld\",\"https:\/\/x.com\/MelanieImfeld\"],\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/author\/mimfeld\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"A Primer for Python Scripting in ArcGIS Insights","description":"Get started with scripting in ArcGIS Insights by learning about our scripting logic and data wrangling workflows","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights","og_locale":"en_US","og_type":"article","og_title":"A Primer for Python Scripting in ArcGIS Insights","og_description":"Get started with scripting in ArcGIS Insights by learning about our scripting logic and data wrangling workflows","og_url":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights","og_site_name":"ArcGIS Blog","article_publisher":"https:\/\/www.facebook.com\/esrigis\/","article_modified_time":"2021-03-24T21:07:19+00:00","twitter_card":"summary_large_image","twitter_site":"@ESRI","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights#article","isPartOf":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights"},"author":{"name":"Melanie Imfeld","@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/c2317c27946a6759eee525497d63901e"},"headline":"A Primer for Python Scripting in ArcGIS Insights","datePublished":"2021-03-23T15:32:27+00:00","dateModified":"2021-03-24T21:07:19+00:00","mainEntityOfPage":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights"},"wordCount":8,"commentCount":0,"publisher":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/#organization"},"keywords":["location analytics","open data","python","spatial analytics","Tutorial"],"articleSection":["Analytics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights","url":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights","name":"A Primer for Python Scripting in ArcGIS Insights","isPartOf":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/#website"},"datePublished":"2021-03-23T15:32:27+00:00","dateModified":"2021-03-24T21:07:19+00:00","description":"Get started with scripting in ArcGIS Insights by learning about our scripting logic and data wrangling workflows","breadcrumb":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/insights\/analytics\/a-primer-for-python-scripting-in-insights#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.esri.com\/arcgis-blog\/"},{"@type":"ListItem","position":2,"name":"A Primer for Python Scripting in ArcGIS Insights"}]},{"@type":"WebSite","@id":"https:\/\/www.esri.com\/arcgis-blog\/#website","url":"https:\/\/www.esri.com\/arcgis-blog\/","name":"ArcGIS Blog","description":"Get insider info from Esri product teams","publisher":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.esri.com\/arcgis-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.esri.com\/arcgis-blog\/#organization","name":"Esri","url":"https:\/\/www.esri.com\/arcgis-blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/Esri.png","contentUrl":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/Esri.png","width":400,"height":400,"caption":"Esri"},"image":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/esrigis\/","https:\/\/x.com\/ESRI","https:\/\/www.linkedin.com\/company\/5311\/"]},{"@type":"Person","@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/c2317c27946a6759eee525497d63901e","name":"Melanie Imfeld","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/image\/","url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/image-213x200.jpg","contentUrl":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/image-213x200.jpg","caption":"Melanie Imfeld"},"description":"Melanie is part of the ArcGIS Insights team and a maps and data visualization enthusiast. Originally from Switzerland, she spent multiple years in Europe working in the area of business intelligence and data driven urban design. Growing up nearby mountains, she is a keen hiker and outdoor lover.","sameAs":["https:\/\/www.linkedin.com\/in\/melanie-imfeld","https:\/\/x.com\/MelanieImfeld"],"url":"https:\/\/www.esri.com\/arcgis-blog\/author\/mimfeld"}]}},"text_date":"March 23, 2021","author_name":"Melanie Imfeld","author_page":"https:\/\/www.esri.com\/arcgis-blog\/author\/mimfeld","custom_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2021\/03\/header_new_2.jpg","primary_product":"ArcGIS Insights","tag_data":[{"term_id":23551,"name":"location analytics","slug":"location-analytics","term_group":0,"term_taxonomy_id":23551,"taxonomy":"post_tag","description":"","parent":0,"count":164,"filter":"raw"},{"term_id":26221,"name":"open data","slug":"open-data","term_group":0,"term_taxonomy_id":26221,"taxonomy":"post_tag","description":"","parent":0,"count":218,"filter":"raw"},{"term_id":24341,"name":"python","slug":"python","term_group":0,"term_taxonomy_id":24341,"taxonomy":"post_tag","description":"","parent":0,"count":171,"filter":"raw"},{"term_id":23391,"name":"spatial analytics","slug":"spatial-analytics","term_group":0,"term_taxonomy_id":23391,"taxonomy":"post_tag","description":"","parent":0,"count":344,"filter":"raw"},{"term_id":27911,"name":"Tutorial","slug":"tutorial","term_group":0,"term_taxonomy_id":27911,"taxonomy":"post_tag","description":"","parent":0,"count":183,"filter":"raw"}],"category_data":[{"term_id":23341,"name":"Analytics","slug":"analytics","term_group":0,"term_taxonomy_id":23341,"taxonomy":"category","description":"","parent":0,"count":1325,"filter":"raw"}],"product_data":[{"term_id":36801,"name":"ArcGIS Insights","slug":"insights","term_group":0,"term_taxonomy_id":36801,"taxonomy":"product","description":"","parent":36591,"count":119,"filter":"raw"}],"primary_product_link":"https:\/\/www.esri.com\/arcgis-blog\/?s=#&products=insights","_links":{"self":[{"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/blog\/1163122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/blog"}],"about":[{"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/types\/blog"}],"author":[{"embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/users\/203542"}],"replies":[{"embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/comments?post=1163122"}],"version-history":[{"count":0,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/blog\/1163122\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/media?parent=1163122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/categories?post=1163122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/tags?post=1163122"},{"taxonomy":"industry","embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/industry?post=1163122"},{"taxonomy":"product","embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/product?post=1163122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}