Google Colab笔记

 

 

1.Google Colab挂载Google Drive并运行程序

from google.colab import drive
drive.mount('/content/drive/')

https://blog.csdn.net/weixin_43792757/article/details/84523103

 

2.利用kaggle的API讲数据集直接下载到Google Colab

登录kaggle在My Account中创建自己的Token:

{"username":"abc","key":"123"}

!pip install -U -q kaggle
!mkdir -p ~/.kaggle
!echo '{"username":"abc","key":"123"}' > ~/.kaggle/kaggle.json
!chmod 600 ~/.kaggle/kaggle.json
#需要注意的是,你必须在kaggle上参加相应的比赛才能下载对应的数据!!!
!kaggle competitions download -c digit-recognizer

https://blog.csdn.net/qq_35654046/article/details/87621396

https://medium.com/@move37timm/using-kaggle-api-for-google-colaboratory-d18645f93648

https://github.com/Kaggle/kaggle-api

 

3.解决google colab环境下使用matplotlib绘图中文乱码问题

从网上下载一个支持中文的字体到系统字体目录:

!wget -O /usr/share/fonts/truetype/liberation/simhei.ttf "http://file3.data.weipan.cn/87016829/e6a4de46faf0c7ba622132eaaad96a291d62f045?ip=1546784382,2409:8a20:203b:550:dbc:11e3:2ef9:cee9&ssig=OSXPXG8otr&Expires=1546784982&KID=sae,l30zoo1wmz&fn=simhei.ttf&se_ip_debug=2409:8a20:203b:550:dbc:11e3:2ef9:cee9&from=1221134"

引入下载的中文字体

import matplotlib.pyplot as plt
import matplotlib as mpl
zhfont = mpl.font_manager.FontProperties(fname='/usr/share/fonts/truetype/liberation/simhei.ttf')
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号

画坐标及坐标轴文本的时候引用

df_Gender=df.groupby("Gender").Purchase.sum().reset_index()
df_Gender=df_Gender.apply(lambda x:x[1]/100000000,axis=1).reset_index(drop=True).reset_index().rename({0:"Purchase"},axis=1)
fig,ax=plt.subplots(figsize=(6,6))
rects=plt.bar(('F','M'),df_Gender.Purchase)
ax.set_xlabel("性别",fontproperties=zhfont)
ax.set_ylabel('亿元',fontproperties=zhfont)
ax.set_ylim((0,45))
ax.set_title("不同性别的总消费额",fontproperties=zhfont)
for rect in rects:
    height = rect.get_height()
    plt.text(rect.get_x() + rect.get_width() / 2, height+0.2, '%.0f'%height, ha='center', va='bottom',fontsize=12,)
plt.show()

效果如下:

参考资料:解决google colab环境下使用matplotlib绘图中文乱码问题

 

转载于:https://www.cnblogs.com/0n-the-way/p/10520644.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值