以下のコードは年月によって訪問数に違いが出るか確かめたいので、リスト(visitor)に格納するための処理コードになります。最終的に時系列データで図出力したいです。
もっと効率の良い(コードを短縮する等)やり方を教えてください。
追記:なぜか図が出力されません。エラーは出てないです。
補足:
air_visit_dfのデータの中身は以下の通りです。
visit_date:年月日データ 例:2016-01-13 2016年1月から2017年4月まであります。
visitors:自然数データ 例:2,4,5・・・
python
1 2visitor=list(0 for i in range(16)) 3 4for ix,i in enumerate(air_visit_df['visit_date']): 5 i=list(i.split("-")) 6 if i[0]=='2016' and i[1]=='01': 7 visitor[0]+= air_visit_df.ix[0]['visitors'] 8 if i[0]=='2016' and i[1]=='02': 9 visitor[1]+= air_visit_df.ix[0]['visitors'] 10 if i[0]=='2016' and i[1]=='03': 11 visitor[2]+= air_visit_df.ix[0]['visitors'] 12 if i[0]=='2016' and i[1]=='04': 13 visitor[3]+= air_visit_df.ix[0]['visitors'] 14 if i[0]=='2016' and i[1]=='05': 15 visitor[4]+= air_visit_df.ix[0]['visitors'] 16 if i[0]=='2016' and i[1]=='06': 17 visitor[5]+= air_visit_df.ix[0]['visitors'] 18 if i[0]=='2016' and i[1]=='07': 19 visitor[6]+= air_visit_df.ix[0]['visitors'] 20 if i[0]=='2016' and i[1]=='08': 21 visitor[7]+= air_visit_df.ix[0]['visitors'] 22 if i[0]=='2016' and i[1]=='09': 23 visitor[8]+= air_visit_df.ix[0]['visitors'] 24 if i[0]=='2016' and i[1]=='10': 25 visitor[9]+= air_visit_df.ix[0]['visitors'] 26 if i[0]=='2016' and i[1]=='11': 27 visitor[10]+= air_visit_df.ix[0]['visitors'] 28 if i[0]=='2016' and i[1]=='12': 29 visitor[11]+= air_visit_df.ix[0]['visitors'] 30 if i[0]=='2017' and i[1]=='01': 31 visitor[12]+= air_visit_df.ix[0]['visitors'] 32 if i[0]=='2017' and i[1]=='02': 33 visitor[13]+=air_visit_df.ix[0]['visitors'] 34 if i[0]=='2017' and i[1]=='03': 35 visitor[14]+=air_visit_df.ix[0]['visitors'] 36 if i[0]=='2017' and i[1]=='04': 37 visitor[15]+=air_visit_df.ix[0]['visitors'] 38VisitorData=pd.DataFrame({'Month':month_list,'visitors':visitor}) 39VisitorData.plot()
回答3件
あなたの回答
tips
プレビュー