<jupyter_start><jupyter_text>Why use the spatially enabled dataframe  In Memory  Fast computation  On the fly indexing  Multi-platform  All the benefits of pandas and more<jupyter_code>import pandas as pd
from arcgis.features import GeoAccessor, GeoSeriesAccessor
from arcgis import GIS
gis = GIS('https://arcgis.com', 'bhammersley_tech')<jupyter_output>Enter password: ········<jupyter_text>Data Wrangling<jupyter_code>df = pd.read_csv(r'C:\Users\bhammersley\OneDrive - ESRI (UK) Ltd\Documents\Presentations\Berlin_2019\data\HH.csv')
df.head()
def f():
    pass

df["full_address"] = df.apply(
                              lambda row: '%s %s %s %s %s' % 
                              (row['Name'],row['Street'],row['Town'],row['County'],row['Postcode']) 
                              if str(row["Name"]) != 'nan' 
    
                              else ('%s %s %s %s %s' % 
                                    (int(row['Number']),row['Street'],row['Town'],row['County'],row['Postcode']) 
                                    if str(row["Number"]) != 'nan' else f()), axis=1)

df = df.drop(['Name', 'Number', 'Street', 'Town', 'County', 'Postcode'], axis=1).dropna().reset_index(drop=True)
df.head()
df.type.value_counts()
df.type = df.type.str.lower()
q = df.type == 'semi-detached'
df.loc[q, 'type'] = 'semi detached'
df.type.value_counts()
sdf = pd.DataFrame.spatial.from_df(df, 'full_address')
sdf.head()<jupyter_output><empty_output><jupyter_text>Visualisation   Matplotlib syntax<jupyter_code>m = gis.map()
m.center = {'spatialReference': {'latestWkid': 3857, 'wkid': 102100},'x': 17740.16697718523,'y': 6833320.7425390035}
m.zoom = 11
m
sdf.spatial.plot(map_widget=m,
                renderer_type='u', # specify the unique value renderer using its notation 'u'
                col='type')  # column to get unique values from
bbox = sdf.spatial.bbox
m.draw(shape = bbox)
sdf.spatial.to_featurelayer('Berlin dev summit houses', gis=gis)<jupyter_output><empty_output><jupyter_text>Geoenrichment<jupyter_code>housing_item = gis.content.get('b92ce1f0a169498f8243056a88564125')
housing_lyr = housing_item.layers[0]
sdf = pd.DataFrame.spatial.from_layer(housing_lyr)
sdf.head()
sdf.spatial.sr
sdf.spatial.project(4326)
analysis_variables = [
    'EDUC01_CY', # 2017 POP age 16+ by Education: No qualifications
    'EDUC02_CY', # 2017 POP age 16+ by Education: Level 1 qualifications
    'EDUC03_CY', # 2017 POP age 16+ by Education: Level 2 qualifications
    'EDUC04_CY', # 2017 POP age 16+ by Education: Level 3 qualifications
    'EDUC05_CY', # 2017 POP age 16+ by Education: Level 4 qualifications and above
    
    'UNEMP_CY', # 2016 unemployed population
    
    'POPDENS_CY', # 2017 population density
    
    'PPPC_CY', # 2017 Purchasing power by capita
    
    'HINC01_CY', # Total households in lowest quintile (below £19,158)
    'HINC01_CY', # Total households in 2nd quintile (£19,158 £28,123)
    'HINC01_CY', # Total households in 3rd quintile (£28,124 to £38,084)
    'HINC01_CY', # Total households in 4th quintile (£38,085 to £54,646)
    'HINC01_CY', # Total households in 5th quintile (£54,646 to £19,158)
    
    'HTYP01A_CY', # Households by type: Single person
    'HTYP02A_CY', # Households by type: Married couple with dependent children
    'HTYP03A_CY', # Households by type: Married couple with no children
    'HTYP04A_CY', # Households by type: Cohabiting couple with dependent children
    'HTYP05A_CY', # Households by type: Cohabiting couple with no dependent children
    'HTYP06A_CY', # Households by type: Single parent with dependent children
    'HTYP07A_CY', # Households by type: Single parent with no dependent children
    'HTYP08A_CY' # Households by type: Other household types
    
]

from arcgis.geoenrichment import enrich

enriched_sdf = enrich(sdf, analysis_variables=analysis_variables)
enriched_sdf.head()
enriched_sdf.spatial.to_featurelayer('enriched houses')<jupyter_output><empty_output>