Intro to Python for Data Science Learning 5 - Packages

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
 

转载于:https://www.cnblogs.com/keepSmile/p/7752594.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值