03 starbucks in seoul

Starbucks in Seoul

  • kaggle에 전세계의 스타벅스의 위치가 데이터가클릭 있어서 이 데이터를 가지고 서울의 스타벅스의 위치를 시각해 보았음
  • 데이터를 보면 스토어의 고유번호, 스토어 이름, 주소, 우편번호, 국가, 도시, 전화번호, GPS경도, GPS 위도가 있음을 확인할 수 있음
  • 서울 데이터의 경우에 데이터에 약간 문제 있고 GPS도 틀린 것이 있지만 그래도 시각화를 시도 해 보았음
  • 지도 시각화는 folium을 사용하였음
In [1]:
##### import pandas as pd

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

df = pd.read_csv('directory.csv')
print(df.columns)
print(df.shape)
df.head(5)
Index(['Brand', 'Store Number', 'Store Name', 'Ownership Type',
       'Street Address', 'City', 'State/Province', 'Country', 'Postcode',
       'Phone Number', 'Timezone', 'Longitude', 'Latitude'],
      dtype='object')
(25600, 13)
Out[1]:
BrandStore NumberStore NameOwnership TypeStreet AddressCityState/ProvinceCountryPostcodePhone NumberTimezoneLongitudeLatitude
0Starbucks47370-257954Meritxell, 96LicensedAv. Meritxell, 96Andorra la Vella7ADAD500376818720GMT+1:00 Europe/Andorra1.5342.51
1Starbucks22331-212325Ajman Drive ThruLicensed1 Street 69, Al JarfAjmanAJAENaNNaNGMT+04:00 Asia/Dubai55.4725.42
2Starbucks47089-256771Dana MallLicensedSheikh Khalifa Bin Zayed St.AjmanAJAENaNNaNGMT+04:00 Asia/Dubai55.4725.39
3Starbucks22126-218024Twofour 54LicensedAl Salam StreetAbu DhabiAZAENaNNaNGMT+04:00 Asia/Dubai54.3824.48
4Starbucks17127-178586Al Ain TowerLicensedKhaldiya Area, Abu Dhabi IslandAbu DhabiAZAENaNNaNGMT+04:00 Asia/Dubai54.5424.51
In [2]:
# 대한민국에 스타벅스는 993개 임을 알 수 있다.
df['Country'].value_counts().head(10)
Out[2]:
US    13608
CN     2734
CA     1468
JP     1237
KR      993
GB      901
MX      579
TW      394
TR      326
PH      298
Name: Country, dtype: int64
In [3]:
#KR로 된 건만 선택함
df_kr = df[df['Country']=='KR']
In [4]:
# city로 조회 하였을 경우에 주소 형식이 통일이 안 되어 있을 알 수 있다.
# 서울은 ['Seoul', '서울',seoul] 로 표기 되어 있음 
df_kr['City'].value_counts().head(10)
Out[4]:
Seoul      243
서울         136
Busan       67
Daegu       38
Daejeon     30
Incheon     29
Gwangju     27
경기도         24
부산          16
Ulsan       16
Name: City, dtype: int64
In [5]:
# 다시 서울 지역만 선택함 
df_se = df_kr[df_kr['City'].isin(['Seoul','서울','seoul'])]
df_se.shape
Out[5]:
(389, 13)
In [6]:
fig, ax = plt.subplots(ncols=1, nrows=1)
fig.set_size_inches(18.5, 10.5)
ax.scatter( df_se.Longitude.values,df_se.Latitude.values,  vmin=1, vmax=8,
           color='blue', s =10, alpha=0.5)

# city_long_border = (126.7, 127.3)
# city_lat_border = (37.4, 37.66)
# ax.set_xlim(city_long_border)
# ax.set_ylim(city_lat_border)
ax.set_xlabel('Longitude')
# ax.set_ylabel('Latitude')
# plt.title('Average speed')
plt.show()
In [7]:
fig, ax = plt.subplots(ncols=1, nrows=1)
fig.set_size_inches(18.5, 10.5)
ax.scatter(  df_se.Longitude.values,df_se.Latitude.values,  vmin=1, vmax=8,
           color='blue', s =20, alpha=0.5)

city_long_border = (126.7, 127.3)
city_lat_border = (37.4, 37.66)
ax.set_xlim(city_long_border)
ax.set_ylim(city_lat_border)
ax.set_xlabel('Longitude')
# ax.set_ylabel('Latitude')
# plt.title('Average speed')
plt.show()
In [8]:
#Latitude > 37.40 이상만 GPS 값이 True이므로 이것만 대상으로 함
df_se_T  = df_se[df_se['Latitude'] >  37.40]
df_se_F  = df_se[df_se['Latitude'] <  37.40]

folium를 사용하면 다음과 같이 지도를 시각화할 수 있음. 자세한 내용은 여기를 참조

In [9]:
import folium
map_osm = folium.Map(location=[37.5, 127], zoom_start=11)
df_se_T.apply(lambda row:folium.CircleMarker(location=[row["Latitude"], row["Longitude"]], 
                                              radius=7, fill_color=('green'))
                                             .add_to(map_osm), axis=1)
map_osm
Out[9]:
In [10]:
 grby_c = df_se_T.groupby(df_se_T.Postcode.str[:3])['Brand','Store Number',].count().reset_index()
In [11]:
# Postcode(우편번호)를 이용하여 구별로 분류하였음
# 135 강남구, 100 중구, 137 서초구 순서로 많음
grby_c.sort_values('Store Number',ascending=False).head(5)
Out[11]:
PostcodeBrandStore Number
101354747
01003434
121373232
11102929
181502222
In [12]:
# 
grby_c = grby_c.sort_values('Store Number',ascending=False).head(25)
plt.pie('Brand', labels = 'Postcode', data = grby_c, autopct= '%1.1f%%', shadow=True)
plt.show()
In [13]:
# 강남구 스타벅스만을 대상으로 
df_135 = df_se_T[df_se_T.Postcode.str[:3]=='135']
In [14]:
df_135.head(5)
Out[14]:
BrandStore NumberStore NameOwnership TypeStreet AddressCityState/ProvinceCountryPostcodePhone NumberTimezoneLongitudeLatitude
7986Starbucks15565-163169Apgujeong CenterJoint Venture639-7, Shinsa-Dong, Gangnam-Gu, Yonsei Foundat...Seoul11KR135-896NaNGMT+09:00 Asia/Seoul127.0437.53
7994Starbucks16277-170084Dosan Main StreetJoint Venture5 Nonhyeon-Dong, Gangnam-Gu, 2FSeoul11KR135-812NaNGMT+09:00 Asia/Seoul127.0237.52
7995Starbucks26311-244130Ulji Hospital SageoriJoint Venture59-8, Nonhyeon 2-dong, Gangnam-guSeoul11KR135-816NaNGMT+09:00 Asia/Seoul127.0337.52
8014Starbucks22689-223665Cheongdam SageoriJoint Venture6-4, Cheongdam-dong, Gangnam-gu, OPUSS11 BuildingSeoul11KR135-949NaNGMT+09:00 Asia/Seoul127.0537.52
8024Starbucks25305-240124Sinsa StationJoint Venture1-3, Nonhyeon-dong, Gangnam-gu,Seoul11KR135-010NaNGMT+09:00 Asia/Seoul127.0237.52
In [ ]:
 
In [15]:
# 강남구를 대상으로 folium에 지도에 표시 함
# GPS(소수점 2자리)로는 정확한 위치를 표시하는 것 불가능함

map_osm=folium.Map(location=[df_135['Latitude'].mean(),df_135['Longitude'].mean()],zoom_start=14)
                             #,tiles='MapQuest Open Aeria
map_osm = folium.Map(location=[df_135['Latitude'].mean(), df_135['Longitude'].mean()], zoom_start=14)
df_135.apply(lambda row:folium.Marker(location=[row["Latitude"], row["Longitude"]], 
                                           popup=folium.Popup(row["Store Name"]))
                                             .add_to(map_osm), axis=1)
map_osm
Out[15]:
In [ ]:
 


© 2017. All rights reserved.

Powered by ZooFighter v0.12