Skip to content

Commit e10d837

Browse files
committed
Use higher level API to import pandas dataframe as a feature collection
1 parent 68361f7 commit e10d837

File tree

1 file changed

+14
-51
lines changed

1 file changed

+14
-51
lines changed

samples/05 Content Publishers/HTML table to Pandas Data Frame to Portal Item.ipynb

Lines changed: 14 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"outputs": [],
3030
"source": [
31-
"df = pd.read_html(\"https://en.wikipedia.org/wiki/Number_of_guns_per_capita_by_country\")[2]"
31+
"df = pd.read_html(\"https://en.wikipedia.org/wiki/Number_of_guns_per_capita_by_country\")[3]"
3232
]
3333
},
3434
{
@@ -371,63 +371,25 @@
371371
"metadata": {
372372
"collapsed": false
373373
},
374-
"outputs": [
375-
{
376-
"name": "stderr",
377-
"output_type": "stream",
378-
"text": [
379-
":0: FutureWarning: IPython widgets are experimental and may change in the future.\n"
380-
]
381-
}
382-
],
374+
"outputs": [],
383375
"source": [
384376
"from arcgis.gis import GIS\n",
385377
"from arcgis.lyr import FeatureCollection\n",
386378
"from arcgis.viz import MapView\n",
387379
"import json\n",
388380
"\n",
389-
"gis = GIS(\"https://deldev.maps.arcgis.com\", \"demo_deldev\", \"P@ssw0rd\")"
381+
"gis = GIS(\"https://deldev.maps.arcgis.com\", \"demo_deldev\", \"P@ssword123\")"
390382
]
391383
},
392384
{
393385
"cell_type": "code",
394386
"execution_count": 11,
395387
"metadata": {
396-
"collapsed": false
388+
"collapsed": true
397389
},
398390
"outputs": [],
399391
"source": [
400-
"path = \"content/features/analyze\"\n",
401-
"postdata = {\n",
402-
" \"f\": \"pjson\",\n",
403-
" \"text\" : df.to_csv(),\n",
404-
" \"filetype\" : \"csv\",\n",
405-
" \"analyzeParameters\" : {\n",
406-
" \"enableGlobalGeocoding\": \"true\",\n",
407-
" \"sourceLocale\":\"en-us\",\n",
408-
" \"locationType\":\"address\",\n",
409-
" \"sourceCountry\":\"\",\n",
410-
" \"sourceCountryHint\":\"\"\n",
411-
" }\n",
412-
"}\n",
413-
"\n",
414-
"\n",
415-
"res = gis._portal.con.post(path, postdata)\n",
416-
"#import json\n",
417-
"#json.dumps(res)\n",
418-
"res['publishParameters'].update({\"addressFields\":{\"CountryCode\":\"Country\"}})\n",
419-
"\n",
420-
"path = \"content/features/generate\"\n",
421-
"postdata = {\n",
422-
" \"f\": \"pjson\",\n",
423-
" \"text\" : df.to_csv(),\n",
424-
" \"filetype\" : \"csv\",\n",
425-
" \"publishParameters\" : json.dumps(res['publishParameters'])\n",
426-
"}\n",
427-
"\n",
428-
"res2014 = gis._portal.con.post(path, postdata, use_ordered_dict=True)\n",
429-
"#print(json.dumps(res2014))\n",
430-
"fc2014 = FeatureCollection(res2014['featureCollection']['layers'][0])"
392+
"fc = gis.content.import_data(df, {\"CountryCode\":\"Country\"})"
431393
]
432394
},
433395
{
@@ -460,7 +422,7 @@
460422
},
461423
"outputs": [],
462424
"source": [
463-
"map.add_layer(fc2014)"
425+
"map.add_layer(fc)"
464426
]
465427
},
466428
{
@@ -476,12 +438,13 @@
476438
" \"tags\" : \"guns,violence\",\n",
477439
" \"snippet\": \" GSR Worldwide gun ownership\",\n",
478440
" \"description\": \"test description\",\n",
479-
" \"text\": json.dumps({\"featureCollection\": {\"layers\": [ fc2014 ]}}),\n",
441+
" \"text\": json.dumps({\"featureCollection\": {\"layers\": [ fc ]}}),\n",
480442
" \"type\": \"Feature Collection\",\n",
481443
" \"typeKeywords\": \"Data, Feature Collection, Singlelayer\",\n",
482444
" \"extent\" : \"-102.5272,-41.7886,172.5967,64.984\"\n",
483445
"}\n",
484-
"item = gis.content.add(item_properties)\n"
446+
"\n",
447+
"item = gis.content.add(item_properties)"
485448
]
486449
},
487450
{
@@ -496,16 +459,16 @@
496459
"text/html": [
497460
"<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n",
498461
" <div class=\"item_left\" style=\"width: 210px; float: left;\">\n",
499-
" <a href='https://deldev.maps.arcgis.com/home/item.html?id=019ab56a1e7a45eead96270ba27c3949' target='_blank'>\n",
462+
" <a href='https://deldev.maps.arcgis.com/home/item.html?id=136ecf570f094c9a84f6e83521bbedf0' target='_blank'>\n",
500463
" <img src='http://static.arcgis.com/images/desktopapp.png' class=\"itemThumbnail\">\n",
501464
" </a>\n",
502465
" </div>\n",
503-
" \n",
466+
"\n",
504467
" <div class=\"item_right\" style=\"float: none; width: auto; overflow: hidden;\">\n",
505-
" <a href='https://deldev.maps.arcgis.com/home/item.html?id=019ab56a1e7a45eead96270ba27c3949' target='_blank'><b>Worldwide gun ownership</b>\n",
468+
" <a href='https://deldev.maps.arcgis.com/home/item.html?id=136ecf570f094c9a84f6e83521bbedf0' target='_blank'><b>Worldwide gun ownership</b>\n",
506469
" </a>\n",
507470
" <br> GSR Worldwide gun ownership<img src='http://www.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/features16.png' style=\"vertical-align:middle;\">Feature Collection by demo_deldev\n",
508-
" <br>Last Modified: June 05, 2016\n",
471+
" <br>Last Modified: July 26, 2016\n",
509472
" <br>0 comments, 0 views\n",
510473
" </div>\n",
511474
" </div>\n",
@@ -541,7 +504,7 @@
541504
"name": "python",
542505
"nbconvert_exporter": "python",
543506
"pygments_lexer": "ipython3",
544-
"version": "3.5.1"
507+
"version": "3.4.4"
545508
},
546509
"widgets": {
547510
"state": {},

0 commit comments

Comments
 (0)