Intro to Python for Data Science Learning 5 - Packages
Packages
Import package
As a data scientist, some notions of geometry never hurt. Let's refresh some of the basics.We can do this by importing package.
import math
# Definition of radius
r = 0.43
# Import the math package
import math
# Calculate C
C = 2 * math.pi * r
# Calculate A
A = math.pi * r ** 2
# Build printout
print("Circumference: " + str(C))
print("Area: " + str(A))
Selective import
General imports, like import math, make all functionality from the mathpackage available to you. However, if you decide to only use a specific part of a package, you can always make your import more selective:
from math import pi
# Definition of radius
r = 192500
# Import radians function of math package
from math import radians #not radians()
# Travel distance of Moon over 12 degrees. Store in dist.
phi = radians(12)
dist = r * phi
# Print out dist
print(dist)
Different ways of importing
There are several ways to import packages and modules into Python. Depending on the import call, you'll have to use different Python code.
Suppose you want to use the function inv(), which is in the linalg subpackage of thescipy package. You want to be able to use this function as follows:
my_inv([[1,2], [3,4]])
could import as:
from scipy.linalg import inv as my_inv
Intro to Python for Data Science Learning 5 - Packages的更多相关文章
- Intro to Python for Data Science Learning 8 - NumPy: Basic Statistics
NumPy: Basic Statistics from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/ch ...
- Intro to Python for Data Science Learning 7 - 2D NumPy Arrays
2D NumPy Arrays from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-4- ...
- Intro to Python for Data Science Learning 2 - List
List from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-2-python-list ...
- Intro to Python for Data Science Learning 6 - NumPy
NumPy From:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-4-numpy?ex=1 ...
- Intro to Python for Data Science Learning 4 - Methods
Methods From:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-3-function ...
- Intro to Python for Data Science Learning 3 - functions
Functions from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-3-functi ...
- Intermediate Python for Data Science learning 2 - Histograms
Histograms from:https://campus.datacamp.com/courses/intermediate-python-for-data-science/matplotlib? ...
- Intermediate Python for Data Science learning 1 - Basic plots with matplotlib
Basic plots with matplotlib from:https://campus.datacamp.com/courses/intermediate-python-for-data-sc ...
- Intermediate Python for Data Science learning 3 - Customization
Customization from:https://campus.datacamp.com/courses/intermediate-python-for-data-science/matplotl ...
随机推荐
- mysql概要(四)order by ,limit ,group by和聚合函数的特点,子查询
1.order by 默认按升序排列(asc/desc),多字段排序 order by 字段 排序方式,字段2 排序方式,..: 在分组排序中,排序是对分组后的结果进行排序,而不是在组中进行排序. s ...
- Unity3D笔记 GUI 三、实现选项卡二窗口
实现目标: 1.使用个性化Box控件 2.个性化Lable控件 3.添加纵向滚动条 4.新建SelectedItem样式 一.最终效果: 二.主要代码 using UnityEngine; using ...
- 7.22 python线程(3)
2018-7-22 10:28:29 回来啦! 6.条件 # !/usr/bin/env python # !--*--coding:utf-8 --*-- # !@Time :2018/7/20 1 ...
- windows下Anaconda3配置TensorFlow深度学习库
Anaconda3(python3.6)安装tensorflow Anaconda3中安装tensorflow3是非常简单的,仅需通过 pip install tensorflow 测试代码: imp ...
- 计蒜客 30990 - An Olympian Math Problem - [简单数学题][2018ICPC南京网络预赛A题]
题目链接:https://nanti.jisuanke.com/t/30990 Alice, a student of grade 6, is thinking about an Olympian M ...
- ubuntu x64 debootstrap
sudo debootstrap jessie /mnt/jessie http://mirrors.163.com/debian
- idea启动tomcat后访问项目报java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
一.报错“java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet” 1.File --- ...
- oracle(十)临时表
1.临时表的特点 (1)多用户操作的独立性:对于使用同一张临时表的不同用户,oracle都会分配一个独立的 Temp Segment,这样就避免了多个用户在对同一张临时表操作时 发生交叉,从而保证了多 ...
- 001-windows下Elasticsearch安装、Elasticsearch-header安装
一.window安装Elasticsearch安装 elasticsearch的客户端版本必须与服务端版本主版本保持一致. 1.java安装[略] 2.elasticsearch下载 地址:https ...
- AngularJS2.0起步
ES6工具链 要让Angular2应用跑起来不是件轻松的事,因为它用了太多还不被当前主流浏览器支持的技术.所以,我们需要一个工具链: