2016-05-02 15 views
1

私はPythonの初心者です。曜日ごとにコミットの数をプロットしようとしています。Github-API:リポジトリへのコミット数をプロットするにはどうすればよいですか?

私はパンダのデータフレームとして出力しています。しかし、私はmatplotlibを使ってこのデータをプロットする方法を理解することができません。

すべてのヘルプは大歓迎です!

import requests 
import json 
import pandas as pd 
r = requests.get('https://api.github.com/repos/thisismetis/dsp/stats/commit_activity') 
raw = r.text 
results = json.loads(raw) 
print pd.DataFrame(results) 

結果:

 days total  week 
0  [0, 0, 0, 0, 0, 0, 0]  0 1431216000 
1  [0, 0, 0, 0, 0, 8, 0]  8 1431820800 
2 [0, 19, 1, 4, 18, 8, 0]  50 1432425600 
3 [0, 3, 23, 1, 0, 0, 0]  27 1433030400 
4  [1, 0, 0, 0, 1, 0, 0]  2 1433635200 
5  [0, 0, 0, 0, 0, 0, 0]  0 1434240000 
6  [0, 2, 0, 0, 0, 0, 0]  2 1434844800 
7  [0, 0, 0, 0, 0, 0, 0]  0 1435449600 
8  [0, 0, 0, 0, 0, 0, 0]  0 1436054400 
9  [0, 0, 0, 0, 0, 0, 0]  0 1436659200 
10 [0, 0, 8, 0, 3, 0, 0]  11 1437264000 
11 [0, 3, 36, 0, 1, 9, 0]  49 1437868800 
12 [0, 2, 2, 2, 5, 1, 0]  12 1438473600 
13 [0, 0, 0, 0, 0, 0, 0]  0 1439078400 
14 [0, 2, 0, 0, 0, 0, 0]  2 1439683200 
15 [0, 0, 0, 0, 0, 0, 0]  0 1440288000 
16 [0, 0, 0, 0, 0, 0, 0]  0 1440892800 
17 [0, 0, 0, 0, 0, 0, 0]  0 1441497600 
18 [0, 0, 0, 0, 0, 3, 0]  3 1442102400 
19 [0, 0, 0, 0, 0, 0, 0]  0 1442707200 
20 [0, 0, 0, 0, 0, 0, 0]  0 1443312000 
21 [0, 0, 0, 0, 0, 0, 0]  0 1443916800 
22 [0, 0, 0, 0, 0, 0, 0]  0 1444521600 
23 [0, 0, 10, 0, 0, 0, 0]  10 1445126400 
24 [0, 0, 0, 0, 0, 0, 0]  0 1445731200 
25 [1, 0, 0, 0, 0, 0, 0]  1 1446336000 
26 [0, 0, 0, 0, 4, 3, 0]  7 1446940800 
27 [0, 0, 0, 0, 0, 0, 0]  0 1447545600 
28 [0, 0, 0, 0, 0, 0, 0]  0 1448150400 
29 [0, 0, 0, 0, 0, 0, 0]  0 1448755200 
30 [0, 0, 0, 0, 0, 0, 0]  0 1449360000 
31 [0, 0, 0, 0, 0, 0, 0]  0 1449964800 
32 [0, 0, 0, 0, 0, 0, 0]  0 1450569600 
33 [0, 0, 0, 0, 0, 0, 1]  1 1451174400 
34 [0, 0, 0, 0, 0, 0, 0]  0 1451779200 
35 [0, 0, 0, 0, 0, 0, 0]  0 1452384000 
36 [0, 0, 0, 0, 0, 0, 0]  0 1452988800 
37 [0, 0, 0, 0, 0, 0, 0]  0 1453593600 
38 [0, 0, 0, 0, 0, 0, 0]  0 1454198400 
39 [0, 0, 5, 2, 0, 0, 0]  7 1454803200 
40 [0, 0, 25, 2, 0, 0, 0]  27 1455408000 
41 [1, 10, 0, 0, 3, 0, 0]  14 1456012800 
42 [0, 0, 0, 0, 0, 0, 0]  0 1456617600 
43 [0, 0, 0, 0, 0, 0, 0]  0 1457222400 
44 [0, 0, 0, 2, 1, 0, 0]  3 1457827200 
45 [0, 0, 0, 0, 0, 0, 0]  0 1458432000 
46 [0, 0, 0, 0, 0, 0, 0]  0 1459036800 
47 [0, 0, 0, 0, 0, 0, 0]  0 1459641600 
48 [0, 0, 0, 0, 0, 0, 0]  0 1460246400 
49 [0, 0, 0, 0, 0, 0, 0]  0 1460851200 
50 [0, 0, 0, 0, 0, 0, 0]  0 1461456000 
51 [0, 0, 0, 0, 0, 0, 0]  0 1462060800 
+0

まさにあなたがプロットしたいですか? – MaxU

+0

私はコミットの数を毎週の曜日(日曜日、月曜日、土曜日)、52週間毎にプロットしたいと思います。私はmatplotlibがpandas dfデータをプロットする方法を理解することができません。 – KeerthiP

+0

https://gist.github.com/tacaswell/e95cb2d57ca3783ffc40セル15と16にはコミット統計データが含まれています。 – tacaswell

答えて

2

は、あなたがこのようにそれを行うことができます。

df['date'] = pd.to_datetime(df.week, unit='s') 
df['week_no'] = df.apply(lambda x: '{:d}-{:02d}'.format(x['date'].year, x['date'].weekofyear), axis=1) 
df.set_index('week_no')['total'].plot.bar() 

enter image description here

+0

ありがとうございました! – KeerthiP

+0

@KeerthiP、いつも助けてうれしい!あなたの質問に答えたと思ったら、[accepting](http://meta.stackexchange.com/a/5235)と答えてください。 – MaxU

+0

私は答えを受け入れる方法を知らなかった;)それを共有してくれてありがとう! – KeerthiP

関連する問題