外贸网站谷歌推广,怎么创建图片网站,呼和浩特哪里做网站,微商城系统销售背景
1、数据集下载
birthsHistorical US birth data culled from the CDC website - jakevdp/data-CDCbirthshttps://github.com/jakevdp/data-CDCbirths
2、数据集介绍
此数据来自美国疾病控制和预防中心#xff0c;并通过 Google 的 BigQuery Web UI 使用以下查询进行编…背景
1、数据集下载
birthsHistorical US birth data culled from the CDC website - jakevdp/data-CDCbirthshttps://github.com/jakevdp/data-CDCbirths
2、数据集介绍
此数据来自美国疾病控制和预防中心并通过 Google 的 BigQuery Web UI 使用以下查询进行编译
SELECTyear, month, day,IF (is_male, M, F) AS gender,SUM(record_weight) as births
FROM[publicdata:samples.natality]
GROUP BYyear, month, day, gender
ORDER BYyear, month, day, gender它被汇总以符合他们的使用条款。 数据于 2015 年 6 月 9 日访问。
请注意Andrew Gelman 和他的小组已经对这些数据进行了相当广泛的分析;参见 this post 英文。
一、读取数据
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
import pandas as pd
from datetime import datetime
%matplotlib inline
二、数据分析预处理
#假期对美国出生率的影响
birthspd.read_csv(./births.csv)
quartiles np.percentile(births[births], [25, 50, 75])
mu, sig quartiles[1], 0.74 * (quartiles[2] - quartiles[0])
births births.query((births mu - 5 * sig) (births mu 5 * sig))
births[day] births[day].astype(int)
births.index pd.to_datetime(10000 * births.year 100 * births.month births.day, format%Y%m%d)
births_by_date births.pivot_table(births,[births.index.month, births.index.day])
births_by_date.index [datetime(2012, month, day)for (month, day) in births_by_date.index]#导入datetime模块
births_by_date.index DatetimeIndex([2012-01-01, 2012-01-02, 2012-01-03, 2012-01-04, 2012-01-05, 2012-01-06, 2012-01-07, 2012-01-08, 2012-01-09, 2012-01-10, ... 2012-12-22, 2012-12-23, 2012-12-24, 2012-12-25, 2012-12-26, 2012-12-27, 2012-12-28, 2012-12-29, 2012-12-30, 2012-12-31], dtypedatetime64[ns], length366, freqNone) 三、可视化
fig,axplt.subplots(figsize(12,4))
births_by_date.plot(axax)
ax.annotate(New Years Day,xy(2012-1-1,4100),xycoordsdata,xytext(50,-30),textcoordsoffset points, arrowpropsdict(arrowstyle-, connectionstylearc3,rad-0.2))
ax.annotate(Independence Day,xy(2012-7-4,4250),xycoordsdata, bboxdict(boxstyleround,fcnone,ecgray), xytext(10,-40),textcoordsoffset points,hacenter, arrowpropsdict(arrowstyle-))
ax.annotate(Labor Day,xy(2012-9-4,4850),xycoordsdata,hacenter, xytext(0,-20),textcoordsoffset points)
ax.annotate(,xy(2012-9-1,4850),xytext(2012-9-7,4850), xycoordsdata,textcoordsdata, arrowprops{arrowstyle:|-|,widthA0.2,widthB0.2,})
ax.annotate(Halloween,xy(2012-10-31,4600),xycoordsdata, xytext(-80,-40),textcoordsoffset points, arrowpropsdict(arrowstylefancy, fc0.6,ecnone, connectionstyleangle3,angleA0,angleB-90))
ax.annotate(Thanksgiving,xy(2012-11-25,4500),xycoordsdata, xytext(-120,-60),textcoordsoffset points, bboxdict(boxstyleround4,pad.5,fc0.9), arrowpropsdict(arrowstyle-, connectionstyleangle,angleA0,angleB80,rad20))
ax.annotate(Christmas,xy(2012-12-25,3850),xycoordsdata, xytext(-30,0),textcoordsoffset points, size13,haright,vacenter, bboxdict(boxstyleround,alpha0.1), arrowpropsdict(arrowstylewedge,tail_width0.5,alpha0.1));
ax.set(titleUSA births by day of year (1969-1988),ylabelaverage daily births)
ax.xaxis.set_major_locator(mpl.dates.MonthLocator())
ax.xaxis.set_minor_locator(mpl.dates.MonthLocator(bymonthday15))
ax.xaxis.set_major_formatter(plt.NullFormatter())
ax.xaxis.set_minor_formatter(mpl.dates.DateFormatter(%h))
ax.set_ylim(3600,5400)
# ax.grid(True)
plt.show() # Plot the results
fig, ax plt.subplots(figsize(8, 6))
births.groupby(dates)[births].mean().plot(axax)# Label the plot
ax.text(2012-1-1, 3950, New Years Day)
ax.text(2012-7-4, 4250, Independence Day, hacenter)
ax.text(2012-9-4, 4850, Labor Day, hacenter)
ax.text(2012-10-31, 4600, Halloween, haright)
ax.text(2012-11-25, 4450, Thanksgiving, hacenter)
ax.text(2012-12-25, 3800, Christmas, haright)
ax.set(titleUSA births by day of year (1969-1988),ylabelaverage daily births,xlim(2011-12-20,2013-1-10),ylim(3700, 5400));# Format the x axis with centered month labels
ax.xaxis.set_major_locator(mpl.dates.MonthLocator())
ax.xaxis.set_minor_locator(mpl.dates.MonthLocator(bymonthday15))
ax.xaxis.set_major_formatter(plt.NullFormatter())
ax.xaxis.set_minor_formatter(mpl.dates.DateFormatter(%h));
ax.set_ylim(3600, 5400)plt.show()