text_html_output_1.png
from mpl_toolkits.basemap import Basemap

from sklearn.cluster import KMeans

import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

air = pd.read_csv('../input/air_reserve.csv')

airvisit = pd.read_csv('../input/air_visit_data.csv')
airvisit['visit_date'] = pd.to_datetime(airvisit['visit_date']).dt.date

airinfo = pd.read_csv('../input/air_store_info.csv')

from sklearn.cluster import KMeans
import matplotlib.pyplot as plt
kmeans = KMeans(n_clusters=10, random_state=0).fit(airinfo[['longitude', 'latitude']])
airinfo['cluster'] = kmeans.predict(airinfo[['longitude', 'latitude']])

from mpl_toolkits.basemap import Basemap
m = Basemap(projection='aeqd',width=2000000,height=2000000, lat_0=37.5, lon_0=138.2)
cx = [c[0] for c in kmeans.cluster_centers_]
cy = [c[1] for c in kmeans.cluster_centers_]
cm = plt.get_cmap('gist_rainbow')
colors = [cm(2.*i/10) for i in range(10)]
colored = [colors[k] for k in airinfo['cluster']]
f,axa = plt.subplots(1,1,figsize=(15,16))
m.drawcoastlines()
m.fillcontinents(color='lightgray',lake_color='aqua',zorder=1)
m.scatter(airinfo.longitude.values,airinfo.latitude.values,color=colored,s=20,alpha=1,zorder=999,latlon=True)
m.scatter(cx,cy,color='Black',s=50,alpha=1,latlon=True,zorder=9999)
plt.setp(axa.get_yticklabels(), visible=True)
plt.annotate('Fukuoka', xy=(0.04, 0.32), xycoords='axes fraction',fontsize=20)
plt.annotate('Shikoku', xy=(0.25, 0.25), xycoords='axes fraction',fontsize=20)
plt.annotate('Hiroshima', xy=(0.2, 0.36), xycoords='axes fraction',fontsize=20)
plt.annotate('Osaka', xy=(0.40, 0.30), xycoords='axes fraction',fontsize=20)

plt.annotate('Tokyo', xy=(0.60, 0.4), xycoords='axes fraction',fontsize=20)
plt.annotate('Shizoku', xy=(0.50, 0.32), xycoords='axes fraction',fontsize=20)

for i in range(len(cx)):
    xpt,ypt = m(cx[i],cy[i])
    plt.annotate(i, (xpt+500,ypt+500),zorder=99999,fontsize=16)
plt.show()

final = pd.merge(airvisit, airinfo).drop(['latitude', 'longitude'], axis=1)

dates = pd.read_csv('../input/date_info.csv')
vdt = pd.to_datetime(final.visit_date)
final['vd'] = vdt.dt.date
final['yday'] = vdt.dt.dayofyear
final['wday'] = vdt.dt.dayofweek
final = final.drop(['vd'], axis=1)
dts = pd.to_datetime(dates.calendar_date)
days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
dates['calendar_date'] = pd.to_datetime(dates['calendar_date']).dt.date
dates['dw'] = [days.index(dw) for dw in dates.day_of_week]
final = pd.merge(final, dates, left_on='visit_date', right_on='calendar_date')

final.head()