<jupyter_start><jupyter_text>HTML table to Pandas Data Frame to Portal ItemOften we read informative articles that present data in a tabular form. If such data contained location information, it would be much more insightful if presented as a cartographic map. Thus this sample shows how Pandas can be used to extract data from a table within a web page (in this case, a Wikipedia article) and how it can be then brought into the GIS for further analysis and visualization.**Note**: to run this sample, you need a few extra libraries in your conda environment. If you don't have the libraries, install them by running the following commands from cmd.exe or your shell```conda install lxmlconda install html5libconda install beautifulsoup4conda install matplotlib```<jupyter_code>import pandas as pd<jupyter_output><empty_output><jupyter_text>Let us read the Wikipedia article on [Estimated number of guns per capita by country](https://en.wikipedia.org/wiki/Number_of_guns_per_capita_by_country) as a pandas data frame object<jupyter_code>df = pd.read_html("https://en.wikipedia.org/wiki/Number_of_guns_per_capita_by_country")[0]<jupyter_output><empty_output><jupyter_text>Let us process the table by dropping some unncessary columns<jupyter_code>df.columns = df.iloc[0]
df = df.reindex(df.index.drop(0))
df.head()<jupyter_output><empty_output><jupyter_text>If you notice, the `Guns per 100 Residents` for United States is not a proper integer. We can correct is as below<jupyter_code>df.iloc[0,2] = 112.6
df.dtypes<jupyter_output><empty_output><jupyter_text>However, we cannot change every incorrect data entry if the table is large. Further we need the `Guns per 100 Residents` column in numeric format. Hence let us convert it and while doing so, convert incorrect values to `NaN` which stands for Not a Number<jupyter_code>converted_column = pd.to_numeric(df["Guns per 100 Residents"], errors = 'coerce')
df['Guns per 100 Residents'] = converted_column
df.head()<jupyter_output><empty_output><jupyter_text>Plot as a mapLet us connect to our GIS to geocode this data and present it as a map<jupyter_code>from arcgis.gis import GIS
import json

gis = GIS("https://www.arcgis.com", "arcgis_python", "<PASSWORD>")
fc = gis.content.import_data(df, {"CountryCode":"Country"})
map1 = gis.map('UK')
map1<jupyter_output><empty_output><jupyter_text>Let us us smart mapping to render the points with varying sizes representing the number of guns per 100 residents<jupyter_code>map1.add_layer(fc, {"renderer":"ClassedSizeRenderer",
               "field_name": "Guns_per_100_Residents"})<jupyter_output><empty_output><jupyter_text>Let us publish this layer as a **feature collection** item in our GIS<jupyter_code>item_properties = {
    "title": "Worldwide gun ownership",
    "tags" : "guns,violence",
    "snippet": " GSR Worldwide gun ownership",
    "description": "test description",
    "text": json.dumps({"featureCollection": {"layers": [dict(fc.layer)]}}),
    "type": "Feature Collection",
    "typeKeywords": "Data, Feature Collection, Singlelayer",
    "extent" : "-102.5272,-41.7886,172.5967,64.984"
}

item = gis.content.add(item_properties)<jupyter_output><empty_output><jupyter_text>Let us search for this item<jupyter_code>search_result = gis.content.search("Worldwide gun ownership")
search_result[0]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09847351092487279, 'fraction_numerical': 0.017360071834780007, 'mean_word_length': 6.265217391304348, 'pattern_counts': {'":': 11, '<': 38, '<?xml version=': 0, '>': 38, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '101322', 'license': 'Apache-2.0', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1035, 'n_words': 341, 'path': 'samples/05_content_publishers/html_table_to_pandas_data_frame_to_portal_item.ipynb', 'repo_name': 'nitz21/arcpy', 'size': '3342'}