python - Github-API : How do I plot the number of commits to a repo?

标签 python api pandas github matplotlib

我是一名 Python 新手,我正在尝试绘制一周中每天的提交数量。

我的输出为 pandas 数据框。但是,我无法弄清楚如何使用 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

最佳答案

你可以这样做:

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

关于python - Github-API : How do I plot the number of commits to a repo?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36986223/

相关文章:

python - CSV 日期解析的 Dask 性能慢?

java - 如何在 Jython 和 PY4J 跨平台中使用 NLTK?

python - 如何减少 if 和 else 的重复使用

python - 如何在python中实现 "cumdot"

api - 我可以通过亚马逊的 API 获得打折的产品吗?

python - 如何将这个数组数组格式化为 pandas 数据框?

python - 通过与 Pandas 中的另一个数据框匹配来替换列表列的有效方法

python - 在 pandas dataframe 中,如何对选定行执行操作?

java - 如何使用 Remember The Milk API 在 Java 中获取 URL?

REST API 心跳标准