于贵洋的博客

BI、数据分析


  • 首页

  • 分类

  • 标签

  • 归档

  • 站点地图

  • 公益404

  • 关于

  • 搜索

爬虫小实例学习篇-猫眼电影

发表于 2017-08-09 | 分类于 Python-爬虫

这里参考了论坛里一位同学分享的博客:猫眼电影TOP100爬取练习,感谢分享。

学习要从模仿开始,学习了上面的博客之后,自己做下练习,正好最近看了selenium,就用了这个。

原作者的正则用的太溜了,等后面有时间再研究下,这里就简单的使用CSS Selector来实现了。

原文代码很精彩,我这个代码就粗糙很多了,先来个初始版,后面再慢慢优化。

大体思路和Python基础(7)- Selenium使用 里面的豆瓣读书例子差不多,

阅读全文 »

matplotlib手册(2)-pyplot.figure

发表于 2017-08-09 | 分类于 数据可视化-Python&R

matplotlib手册(2)

这里,我们继续上一节,继续学习下pyplot
参考官方文档:http://matplotlib.org/2.0.2/users/pyplot_tutorial.html

1. pyplot.figure

我暂时是把他理解成画板的意思,前面我们虽然没有使用figure,但是默认会创建一个figure

1
2
3
4
5
6
7
8
matplotlib.pyplot.figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True, FigureClass=<class 'matplotlib.figure.Figure'>, **kwargs)
#这里有几个常用的参数,比如num,这就好比是一个id,来表示每一个figure
num : integer or string, optional, default: none
#画板的大小
figsize : tuple of integers, optional, default: None
#表示画板的背景颜色
facecolor :the background color. If not provided, defaults to rc figure.facecolor

我们来个小例子,我们就创建3个figure,修改背景颜色,不做其他的

1
2
3
4
5
6
7
8
9
10
import matplotlib.pyplot as plt
plt.figure('one' ,facecolor='green')
plt.figure('two' ,facecolor='red')
plt.figure('three' ,facecolor='blue')
plt.show()

阅读全文 »

numpy手册(4)-ufunc

发表于 2017-08-08 | 分类于 Python-Numpy

Python
Numpy知识总结


这里,我们说下对数组操作的常用函数

常用函数

我们先说下接收一个参数的一元函数,比如 np.sqrt 开方函数

1
2
3
4
5
6
7
8
9
10
11
a = np.arange(10)
np.sqrt(a)
Out[45]:
array([ 0. , 1. , 1.41421356, 1.73205081, 2. ,
2.23606798, 2.44948974, 2.64575131, 2.82842712, 3. ])
a**0.5
Out[46]:
array([ 0. , 1. , 1.41421356, 1.73205081, 2. ,
2.23606798, 2.44948974, 2.64575131, 2.82842712, 3. ])

常用的一元函数
常用一元函数

常用一元函数

还有些常用的二元函数,比如 add,subtract

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
a = np.array([1,2,3])
b = np.array([4,5,6])
a
Out[49]: array([1, 2, 3])
b
Out[50]: array([4, 5, 6])
np.add(a,b)
Out[51]: array([5, 7, 9])
np.subtract(a,b)
Out[52]: array([-3, -3, -3])

常用二元函数

阅读全文 »

matplotlib手册(1)-pyplot使用

发表于 2017-08-08 | 分类于 数据可视化-Python&R

matplotlib手册(1)

最近开始看看Pandas中可视化的部分,主要是使用matplotlib,这里,我们先从pyplot开始。
主要参考官方教程:Pyplot tutorial
我们从一个最简单的例子开始

1
2
3
4
5
6
7
8
import matplotlib.pyplot as plt
#
plt.plot([1,2,3,4])
#指定y轴标签
plt.ylabel('some numbers')
#展示图片
plt.show()

只要几行代码,就显示了一个图形,我们观察一下这个图,会发现,y轴是1到4,而x轴是1到3,这是由于我们传入的参数导致的
plot([1,2,3,4]),这里呢,我们只传了一个数组,matplotlib会默认当做y轴的值,x轴是默认分配的,Python中ranges默认是从0开始的,所以x轴从0-3
我们也可以指定x轴的值

1
2
3
4
5
6
7
8
9
10
import matplotlib.pyplot as plt
#默认是y轴的值
#plt.plot([1,2,3,4])
#传入x轴,y轴
plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
#指定y轴标签
plt.ylabel('some numbers')
#展示图片
plt.show()

matplotlib.pyplot.plot(args, *kwargs)

阅读全文 »

使用Spyder不弹出画图面板

发表于 2017-08-08 | 分类于 数据可视化-Python&R

最近练习Python都是在Spyder中开发,很方便,今天练习matplotlib的时候,发现,绘制的图片显示在out中

1
2
3
4
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()

依稀记得之前在IPython中执行的时候,是单独弹出一个面板的,就百度了下,找到了解决方法
我们在Tools->Preferences->

阅读全文 »
1…131415…23
于贵洋

于贵洋

111 日志
17 分类
30 标签
RSS
GitHub
友情链接
  • 很久之前的CSDN博客
0%
© 2017 于贵洋
由 Hexo 强力驱动
|
主题 — NexT.Pisces v5.1.3
Hosted by GitHub Pages
本站访客数 人次 本站总访问量 次