# Weekly Challenge

Solve the challenge, share your solution and summit the ranks of our Community!
###### IDEAS WANTED

We're actively looking for ideas on how to improve Weekly Challenges and would love to hear what you think!

Submit Feedback
We've recently made an accessibility improvement to the community and therefore posts without any content are no longer allowed. Please use the spoiler feature or add a short message in the message body in order to submit your weekly challenge.

## Challenge #197: Customer Density Reporting

Highlighted
8 - Asteroid
Spoiler
Highlighted
8 - Asteroid
Spoiler
Solution Attached

Highlighted
12 - Quasar

Spatial Donut works well for this one:

Spoiler

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

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

Highlighted
7 - Meteor

Sweet, spatial analytics and report tools--two things I haven't needed to use at all so far, so glad to learn more.

Spoiler

Spoiler

Spoiler

Highlighted
11 - Bolide
Spoiler

Highlighted
8 - Asteroid

good times!! that's was fun.. if anyone actually looks sorry for the messy workflow!

Highlighted
12 - Quasar

my solution

Highlighted
11 - Bolide
Spoiler

If you could just go ahead and like, that'll be great!!

Highlighted
10 - Fireball

My solution is attached!

I feel like I have way too many tools.

Spoiler
End product

Highlighted
8 - Asteroid

I like it.

Spoiler