Packages

From:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-3-functions-and-packages?ex=10

  • 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的更多相关文章

  1. 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 ...

  2. 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- ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Intermediate Python for Data Science learning 2 - Histograms

    Histograms from:https://campus.datacamp.com/courses/intermediate-python-for-data-science/matplotlib? ...

  8. 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 ...

  9. Intermediate Python for Data Science learning 3 - Customization

    Customization from:https://campus.datacamp.com/courses/intermediate-python-for-data-science/matplotl ...

随机推荐

  1. pip安装python包出现Cannot fetch index base URL http://pypi.python.org/simple/

    pipinstall***安装python包,出现 Cannot fetch index base URL  http://pypi.python.org/simple /错误提示或者直接安装不成功. ...

  2. 总结一下最近用到的技术(2)--JsonSchema和JsonSchemaValidator

    我们最早接触xml的时候会使用一个dtd文件去定义xml里可以有哪些元素和属性等,后来发展到xml schama(是一个xsd文件,在dtd的基础上提供了命名空间等更强大的功能) 现在,RESTful ...

  3. VS2003安装Opencv1.0 windows系统 win7

    一.步骤 下载安装opencv1.0     安装文件我上传到百度网盘分享连接 http://pan.baidu.com/s/1o8na0aA 配置电脑windows环境变量 配置VS2003全局设置 ...

  4. 安装 SQL SERVER MsiGetProductInfo 无法检索 Product Code 1605错误 解决方案

    重装数据库服务器上的SQL SERVER 2008 上遇到了以下问题 标题: SQL Server 安装程序失败. SQL Server 安装程序遇到以下错误: MsiGetProductInfo 无 ...

  5. Office2010安装需要MSXML版本6.10.1129.0的方法

    今天给朋友装Office2010,由于朋友之前使用的是绿化版的0ffice2007,所以卸载后安装Office遇到了若要安装Office2010,需要在计算机上安装MSXML版本6.10.1129.0 ...

  6. 关于Thinkphp访问不正常的问题

    最近遇见了个蹩脚的问题,我放在服务器的项目(thinkphp框架)只能访问默认路径内容,不管你url怎么写的,他就访问默认那个文件.. 对于有强迫症的我来说实在是欺人太甚!!! 于是乎我就抓耳挠腮了. ...

  7. 为VS定制一个自己的代码生成器 - 自定义工具开发

    自定义工具开发 为VS定制一个自己的代码生成器 如何在Visual Studio中开发自己的代码生成器插件 你必须懂的 T4 模板:深入浅出 Regasm组件注册工具使用方法 Regasm 注册C# ...

  8. h5直播

    直播开发之旅 ① 状态控制: 目前我们先考虑直播的三种状态: 直播前,直播中,结束. 针对每个状态我们肯定会有不同的显示,这三种状态可以是三个页面,相互切换,或者一个页面,控制页面相关隐藏和显示. 可 ...

  9. Cloud Native Application理论备忘录之(一)——Microservice architectural style

    感谢一路走来默默支持和陪伴的你~~~ ------------------欢迎来访,拒绝转载------------------- 1. 传统云平台的架构体系:用户界面层.业务逻辑层.数据访问层 2. ...

  10. 多态设计 zen of python poem 显式而非隐式 延迟赋值

    总结 1.python支持延迟赋值,但是给调用者带来了困惑: 2.显式而非隐式,应当显式地指定要初始化的变量 class Card: def __init__(self, rank, suit): s ...