杨韬的Python/Jupyter学习笔记
- Python语法学习 https://zhuanlan.zhihu.com/p/24162430
Python 安装库
安装Jupyter Notebook
- 先安装Python
- cmd 进入K:\Jupyter Notebook Python\Python_3.6.4\Scripts目录
- cmd 输入 pip install jupyter 开始安装
- 运行 Python_3.6.4\Scripts下的 jupyter-notebook.exe
安装numpy 数学包
到https://pypi.python.org/pypi/numpy#downloads 下载对应版本的numpy-1.14.0-cp36-none-win_amd64.whl 文件,复制到Scripts目录下安装
cmd运行 在K:\Jupyter Notebook Python\Python_3.6.4\Scripts>pip install numpy-1.14.0-cp36-none-win_amd64.whl
安装绘图包matplotlib
- cmd 输入 pip install matplotlib
安装pandas 数据输入输出库
- cmd 输入 pip install pandas
安装seaborn绘图库
- cmd 输入 pip install seaborn
pip安装命令
安装 pip install jupyterthemes
安装最新版本 pip install --upgrade jupyterthemes
安装指定版本 pip install jupyterthemes==0.18.3
实际上pip instal 既可以安装本地.whl 也可以在线安装
若在线安装失败,如UnicodeDecodeError: 'gbk' codec can't decode 这类问题。可能需要安装之前的指定版本
import math
math.sin(3)
0.1411200080598672
words = ['cat', 'window', 'defenestrate']
for w in words:
print("单词 "+w, "长度"+str(len(w)))
单词 cat 长度3
单词 window 长度6
单词 defenestrate 长度12
# 绘图包 matplotlib 的使用
# https://liam0205.me/2014/09/11/matplotlib-tutorial-zh-cn/
# http://codingpy.com/article/a-quick-intro-to-matplotlib/
import matplotlib.pyplot as plt # 需要先包含绘图包
import numpy as np
x = np.arange(20)
y = x**2
plt.plot(x, y)
plt.show() # 显示图形
#参考 http://codingpy.com/article/a-quick-intro-to-matplotlib/
$$ \int_0^{+\infty} x^2 dx $$
# 自定义曲线的外观
x = np.linspace(0, 2 * np.pi, 50)
plt.plot(x, np.sin(x), 'r-o',
x, np.cos(x), 'g--') # r g 颜色 - 线型
plt.show()
# 彩色映射散点图
x = np.random.rand(1000)
y = np.random.rand(1000)
size = np.random.rand(1000) * 50
colour = np.random.rand(1000)
plt.scatter(x, y, size, colour) # 散点图
plt.colorbar() #颜色栏
plt.show()

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
np.random.seed(42)
# 采样个数500
n_samples = 500
dim = 3
# 先生成一组3维正态分布数据,数据方向完全随机
samples = np.random.multivariate_normal(
np.zeros(dim),
np.eye(dim),
n_samples
)
# 通过把每个样本到原点距离和均匀分布吻合得到球体内均匀分布的样本
for i in range(samples.shape[0]):
r = np.power(np.random.random(), 1.0/3.0)
samples[i] *= r / np.linalg.norm(samples[i])
upper_samples = []
lower_samples = []
for x, y, z in samples:
# 3x+2y-z=1作为判别平面
if z > 3*x + 2*y - 1:
upper_samples.append((x, y, z))
else:
lower_samples.append((x, y, z))
fig = plt.figure('3D scatter plot')
ax = fig.add_subplot(111, projection='3d')
uppers = np.array(upper_samples)
lowers = np.array(lower_samples)
# 用不同颜色不同形状的图标表示平面上下的样本
# 判别平面上半部分为红色圆点,下半部分为绿色三角
ax.scatter(uppers[:, 0], uppers[:, 1], uppers[:, 2], c='r', marker='o')
ax.scatter(lowers[:, 0], lowers[:, 1], lowers[:, 2], c='g', marker='^')
plt.show()
# 参考 https://zhuanlan.zhihu.com/p/24309547
使用pandas数据输入输出库
参考 http://python.jobbole.com/80853/
import pandas as pd
df = pd.DataFrame({ 'A' : 1.,
'B' : pd.Timestamp('20130102'),
'C' : pd.Series(1, index=list(range(4)), dtype='float32'),
'D' : pd.Series([1, 2, 1, 2], dtype='int32'),
'E' : pd.Categorical(["test", "train", "test", "train"]),
'F' : 'foo' })
df
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
A | B | C | D | E | F | |
---|---|---|---|---|---|---|
0 | 1.0 | 2013-01-02 | 1.0 | 1 | test | foo |
1 | 1.0 | 2013-01-02 | 1.0 | 2 | train | foo |
2 | 1.0 | 2013-01-02 | 1.0 | 1 | test | foo |
3 | 1.0 | 2013-01-02 | 1.0 | 2 | train | foo |
df.B
0 2013-01-02
1 2013-01-02
2 2013-01-02
3 2013-01-02
Name: B, dtype: datetime64[ns]
使用Seaborn绘图库
Seaborn本质上使用Matplotlib作为核心库,默认情况下就能创建赏心悦目的图
# http://python.jobbole.com/80853/
import seaborn as sns
# Load one of the data sets that come with seaborn
tips = sns.load_dataset("tips")
sns.jointplot("total_bill", "tip", tips, kind='reg');
tips.head()
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
total_bill | tip | sex | smoker | day | time | size | |
---|---|---|---|---|---|---|---|
0 | 16.99 | 1.01 | Female | No | Sun | Dinner | 2 |
1 | 10.34 | 1.66 | Male | No | Sun | Dinner | 3 |
2 | 21.01 | 3.50 | Male | No | Sun | Dinner | 3 |
3 | 23.68 | 3.31 | Male | No | Sun | Dinner | 2 |
4 | 24.59 | 3.61 | Female | No | Sun | Dinner | 4 |
sns.lmplot("total_bill", "tip", tips, col="smoker");
其它参考
http://blog.csdn.net/qq_34264472/article/details/53814653
https://www.cnblogs.com/kylinlin/p/5236601.html
http://blog.csdn.net/u013082989/article/details/73278458
https://www.cnblogs.com/gczr/p/6767175.html
Python·Jupyter Notebook各种使用方法记录
http://blog.csdn.net/tina_ttl/article/details/51031113
Jupyter更换主题
https://github.com/dunovank/jupyter-themes
安装主题
- pip install jupyterthemes
若出现UnicodeDecodeError: 'gbk' 中文问题,可安装之前的版本
pip install jupyterthemes==0.18.3
查看已安装带主题
- 命令行 jt -l
应用主题
- 命令行 jt -t onedork -f fira -fs 13
-fs 13 字体
回复原始状态
- jt -r
# 嵌入视频
from IPython.display import VimeoVideo
VimeoVideo("63250251",with=600, height=400)
File "<ipython-input-21-5e0fd48278da>", line 3
VimeoVideo("63250251",with=600, height=400)
^
SyntaxError: invalid syntax
# 交互图表
import ipywidgets
a=ipywidgets.IntSlider(value=5,min=0, max=10, step=1)
a
ipywidgets.Text()
# 嵌入HTML页面
from IPython.display import HTML
HTML('<iframe src="https://www.baidu.com" width=800 height=400></iframe>')
# 运行外部.py程序
# %run xxxx/xxxx.py
# Geo-Json
安装jupyter lab Python IDE
- pip install jupyterlab
执行 jupyter lab
杨韬的Python/Jupyter学习笔记的更多相关文章
- 【原】Learning Spark (Python版) 学习笔记(三)----工作原理、调优与Spark SQL
周末的任务是更新Learning Spark系列第三篇,以为自己写不完了,但为了改正拖延症,还是得完成给自己定的任务啊 = =.这三章主要讲Spark的运行过程(本地+集群),性能调优以及Spark ...
- Python Click 学习笔记(转)
原文链接:Python Click 学习笔记 Click 是 Flask 的团队 pallets 开发的优秀开源项目,它为命令行工具的开发封装了大量方法,使开发者只需要专注于功能实现.恰好我最近在开发 ...
- 0003.5-20180422-自动化第四章-python基础学习笔记--脚本
0003.5-20180422-自动化第四章-python基础学习笔记--脚本 1-shopping """ v = [ {"name": " ...
- Python Flask学习笔记之模板
Python Flask学习笔记之模板 Jinja2模板引擎 默认情况下,Flask在程序文件夹中的templates子文件夹中寻找模板.Flask提供的render_template函数把Jinja ...
- Python Flask学习笔记之Hello World
Python Flask学习笔记之Hello World 安装virtualenv,配置Flask开发环境 virtualenv 虚拟环境是Python解释器的一个私有副本,在这个环境中可以安装私有包 ...
- 获取字段唯一值工具- -ArcPy和Python案例学习笔记
获取字段唯一值工具- -ArcPy和Python案例学习笔记 目的:获取某一字段的唯一值,可以作为工具使用,也可以作为函数调用 联系方式:谢老师,135-4855-4328,xiexiaokui# ...
- Python高级学习笔记
Python高级学习笔记,此笔记中包含Linux操作系统.Html+CSS+JS.网络协议等. 所有思维导图为本人亲手所画,请勿用于商用. 大哥们,求点赞哦. 第一天笔记:链接 第二天笔记:链接 第三 ...
- python爬虫学习笔记(一)——环境配置(windows系统)
在进行python爬虫学习前,需要进行如下准备工作: python3+pip官方配置 1.Anaconda(推荐,包括python和相关库) [推荐地址:清华镜像] https://mirrors ...
- Python入门学习笔记4:他人的博客及他人的学习思路
看其他人的学习笔记,可以保证自己不走弯路.并且一举两得,即学知识又学方法! 廖雪峰:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958 ...
随机推荐
- Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project demo: Fatal error com piling: 无效的标记: -parameters
背景:本项目使用JDK1.8 编译maven工程的时候出现如下错误: Failed to execute goal org.apache.maven.plugins:maven-compiler-pl ...
- Qt编写自定义控件9-导航按钮控件
前言 导航按钮控件,主要用于各种漂亮精美的导航条,我们经常在web中看到导航条都非常精美,都是html+css+js实现的,还自带动画过度效果,Qt提供的qss其实也是无敌的,支持基本上所有的CSS2 ...
- F - Rescue 优先队列bfs
来源poj Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a ...
- sqoop/1.4.6/下载
http://archive.apache.org/dist/sqoop/1.4.6/
- Java远程连接redis, 报错 Connection refused: connect
在今天的学习Redis中报错 Connection refused: connect 我总结了有三种情况: 1.远程服务器中的Redis没有开启. 2.远程连接地址出错,或者是端口出错. 3.远程服务 ...
- 关于ie浏览器信任站点的代码
1检测用户当前浏览器是否将域名的ip添加信任站点 js代码 //域名ip的获取 var hostname = window.location.hostname; var WshShell ...
- 学习 ASP.NET Core 2.1:集成测试中使用 WebApplicationFactory
WebApplicationFactory 是 ASP.NET Core 2.1 新特性 MVC functional test infrastructure 中带来的新东东,它封装了 TestSer ...
- day19:常用模块(collections,time,random,os,sys)
1,正则复习,re.S,这个在用的最多,re.M多行模式,这个主要改变^和$的行为,每一行都是新串开头,每个回车都是结尾.re.L 在Windows和linux里面对一些特殊字符有不一样的识别,re. ...
- iOS系统NSNotificationCenter中的常用通知名称
//音频 AVF_EXPORT NSString *const AVAudioSessionInterruptionNotification //音频中断出现 AVF_EXPORT NSString ...
- Yarn vs npm: 你需要知道的一切(转)
英文原文:https://www.sitepoint.com/yarn-vs-npm/ 译文:http://web.jobbole.com/88459/ Yarn 是 Facebook, Google ...