Want to get involved? We're always looking for ideas and content for Weekly Challenges.
SUBMIT YOUR IDEA
Spatial Donut works well for this one:
and Python:
#################################
from ayx import Alteryx
import pandas as pd
from geopy import distance
import great_circle_calculator.great_circle_calculator as gcc
import math
office = Alteryx.read('Office')
customers = Alteryx.read('Customers')
def dfappend(df1,df2):
df1['dfappkey'] = 1
df2['dfappkey'] = 1
df = pd.merge(df1, df2, on='dfappkey')
del df['dfappkey']
return df
customers = dfappend(customers,office)
customers['point1'] = '('+customers['Lat'].map(str)+', '+customers['Lon'].map(str)+')'
customers['point2'] = '('+customers['Latitude'].map(str)+', '+customers['Longitude'].map(str)+')'
def calc_dist(x):
point1 = (x.Lat, x.Lon)
point2 = (x.Latitude, x.Longitude)
return distance.distance(point1, point2).miles
customers['milesFrom'] = customers.apply(calc_dist, axis=1)
customers_0to5 = customers.query('milesFrom < 5')
customers_0to5 = customers_0to5.groupby('Customer Segment').agg({'Lon': 'count'})
customers_0to5 = customers_0to5.rename(columns={'Lon':'Number of Customers'}).reset_index()
customers_0to5['Customer Density'] = customers_0to5['Number of Customers']/(math.pi*5**2)
customers_5to8 = customers.query('milesFrom >= 5 and milesFrom < 8')
customers_5to8 = customers_5to8.groupby('Customer Segment').agg({'Lon': 'count'})
customers_5to8 = customers_5to8.rename(columns={'Lon':'Number of Customers'}).reset_index()
customers_5to8['Customer Density'] = customers_5to8['Number of Customers']/((math.pi*8**2)-(math.pi*5**2))
Alteryx.write(customers_0to5,1)
Alteryx.write(customers_5to8,2)
#################################
#SnakingMyWayThruChallenges
If you could just go ahead and like, that'll be great!!
I like it.