Github社区python项目数据分析

引言

最近看到CSDN上各种做数据分析的,相关博文层出不穷:什么分析CSDN小姐姐一年发的文章,什么分析猎场的火热程度,比比皆是。于是乎,我们也来凑个热闹,分析下github上火热的python项目。

使用API调用数据

首先我们打开自己的浏览器,在地址栏中输入下面的命令:

https://api.github.com/search/repositories?q=language:python&sort=stars

然后我们会得到下面的信息(信息会更新,你们得到的可能与我的不同):
这里写图片描述

首先我们来解释下咱们的https调用,第一部分(https://api.github.com/)是将请求发送带github网站中响应API的部分;接下来的一部分(search/repositories)是让API搜索Github中所有的仓库。repositories后面的问好指出了我们要传递的第一个实参。q=表示查询,language:python表示查询项,&sort=stars,表示查询结果按照stars排序。

从我们张贴的图片可知:
现在github上面总共有2274030个项目,items下面就是最受欢迎的项目了。

处理API响应

接下来我们需要借助request库来请求API响应,并获取最受欢迎的github项目信息:

r = requests.get(url)


# In[11]:

print("Status code:",r.status_code)


# In[12]:

response_dict = r.json()


# In[14]:

print(response_dict.keys())


# In[15]:

print("Total repositories:", response_dict['total_count'])


# In[16]:

# Explore information about the repositories.
repo_dicts = response_dict['items']
print("Repositories returned:",len(repo_dicts))


# In[17]:

repo_dict = repo_dicts[0]
print("\nKeys:",len(repo_dict))
for key in sorted(repo_dict.keys()):
    print(key)


# In[18]:

print("\nSelected information about first repository:")
print('Name:',repo_dict['name'])
print('Owner:',repo_dict['owner']['login'])
print('Stars:',repo_dict['stargazers_count'])
print('Repository:',repo_dict['html_url'])
print('Created:',repo_dict['created_at'])
print('Updated:',repo_dict['updated_at'])
print('Description:',repo_dict['description'])

信息如下:
这里写图片描述
其中我们可以或者,最受欢迎的项目名称为:awesome-python,创建于2014年,截止到我写这篇博客时,依旧有更新,图片最后一行是对这个项目的描述:一组很棒的Python框架、库、软件和资源的列表。所以,这就是个各个python资料的链接中心。。。

利用pygal可视化受欢迎的github仓库

这里我们要创建一个交互式的条形图svg:条形图高度表示了项目获得了多少颗星。单击条形图还能跳转到项目在github上的主页。图片如下:
这里写图片描述

项目源码

github : 传送门

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Roaring Kitty

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值