03 starbucks in seoul
| 18 Minute Read on Visualization
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)
Out[1]:
In [2]:
# 대한민국에 스타벅스는 993개 임을 알 수 있다.
df['Country'].value_counts().head(10)
Out[2]:
In [3]:
#KR로 된 건만 선택함
df_kr = df[df['Country']=='KR']
In [4]:
# city로 조회 하였을 경우에 주소 형식이 통일이 안 되어 있을 알 수 있다.
# 서울은 ['Seoul', '서울',seoul] 로 표기 되어 있음
df_kr['City'].value_counts().head(10)
Out[4]:
In [5]:
# 다시 서울 지역만 선택함
df_se = df_kr[df_kr['City'].isin(['Seoul','서울','seoul'])]
df_se.shape
Out[5]:
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]:
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]:
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 [ ]: