ThinkStats (3)
とりあえずお仕事対応は終了ってことで、こちら対応着手。
次は演習 1-3-4 か。折角 git 使ってるんだから盛り込み順で commit 作るか。とりあえず、
- 最初の状態で commit 作成
- 1-3-1 の状態で commit 作成
- 1-3-2 の状態で commit 作成
で、1-3-3 を云々しとるのですがこれで良いのかどうなのか。
# -*- coding: utf-8 -*- import survey table = survey.Pregnancies() table.ReadRecords() first = 0 other = 0 for i in table.records: if i.birthord == 1: first += 1 elif i.birthord <= 10: other += 1 print u' 第一子:', first print u' 第二子以降:', other
なんか今朝方 (というか昨晩) のエントリがもの凄い勢いでナチュラルなんですがどうしたものか。次は 1.3.4 ですね。
妊娠期間は prglength ってことで、ってよく考えてみるに 1-3-3 は以下なのか。
# -*- coding: utf-8 -*- import survey table = survey.Pregnancies() table.ReadRecords() first = 0 other = 0 for i in table.records: if i.outcome == 1: if i.birthord == 1: first += 1 else: other += 1 print u' 第一子:', first print u' 第二子以降:', other
commit 作っとこ。つうことはこれを元にできるな。で、1-3-4 は以下をでっちあげたのですが変わりなし。
# -*- coding: utf-8 -*- import survey table = survey.Pregnancies() table.ReadRecords() first_count = 0 first_prglength = 0 other_count = 0 other_prglength = 0 for i in table.records: if i.outcome == 1: if i.birthord == 1: first_count += 1 first_prglength += i.prglength else: other_count += 1 other_prglength += i.prglength print u' 第一子妊娠期間の平均:', first_prglength/first_count print u' 第二子以降妊娠期間の平均:', other_prglength/other_count
これを実行すると以下。
$ python first.py 第一子妊娠期間の平均: 38 第二子以降妊娠期間の平均: 38
で、テキスト見たら 13h 遅れて云々との記述あり。え、時間にするのはアレだなぁ。しかも 13h とかって誤差の範疇ではないのか、と言いつつ実装を修正。
# -*- coding: utf-8 -*- import survey table = survey.Pregnancies() table.ReadRecords() first_count = 0 first_prglength = 0 other_count = 0 other_prglength = 0 for i in table.records: if i.outcome == 1: if i.birthord == 1: first_count += 1 first_prglength += i.prglength * 7 * 24 else: other_count += 1 other_prglength += i.prglength * 7 * 24 print u' 第一子妊娠期間の平均:', first_prglength/first_count print u' 第二子以降妊娠期間の平均:', other_prglength/other_count
で、実行してみると出力が以下。
$ python first.py 第一子妊娠期間の平均: 6484 第二子以降妊娠期間の平均: 6471
commit を作って燃料を入れつつ先を確認の方向。