>>>import numpy as np
>>> a = np.arange(15).reshape(3,5)>>> a
array([[0,1,2,3,4],[5,6,7,8,9],[10,11,12,13,14]])>>> a.shape
(3,5)>>> a.ndim
2>>> a.dtype.name
'int64'>>> a.itemsize
8>>> a.size
15>>>type(a)<class'numpy.ndarray'>>>> b = np.array([6,7,8])>>> b
array([6,7,8])>>>type(b)<class'numpy.ndarray'>
import pendulum
now = pendulum.now("Europe/Paris")# Changing timezone
now.in_timezone("America/Toronto")# Default support for common datetime formats
now.to_iso8601_string()# Shifting
now.add(days=2)
from PIL import Image
#Open image using Image module
im = Image.open("images/cuba.jpg")#Show actual Image
im.show()#Show rotated Image
im = im.rotate(45)
im.show()
from skimage.filters import gaussian_filter
from moviepy.editor import VideoFileClip
defblur(image):""" Returns a blurred (radius=2 pixels) version of the image """return gaussian_filter(image.astype(float), sigma=2)
clip = VideoFileClip("my_video.mp4")
clip_blurred = clip.fl_image( blur )
clip_blurred.write_videofile("blurred_video.mp4")
Requests Python程序包(座右铭:“ HTTP for Humans”)通过自动执行许多繁琐的任务来解决此问题,让发送HTTP请求变得异常简单。它消除了添加查询字符串或执行POST表单编码的需要。它还可以使与HTTP服务器的连接自动保持活动状态,从而无需编写大量代码。
import requests
from requests.exceptions import HTTPError
for url in['https://api.github.com','https://api.github.com/invalid']:try:
response = requests.get(url)# If the response was successful, no Exception will be raised
response.raise_for_status()except HTTPError as http_err:print(f'HTTP error occurred: {http_err}')# Python 3.6except Exception as err:print(f'Other error occurred: {err}')# Python 3.6else:print('Success!')
In [5]: dates = pd.date_range("20130101", periods=6)
In [6]: dates
Out[6]:
DatetimeIndex(['2013-01-01','2013-01-02','2013-01-03','2013-01-04','2013-01-05','2013-01-06'],
dtype='datetime64[ns]', freq='D')
In [7]: df = pd.DataFrame(np.random.randn(6,4), index=dates, columns=list("ABCD"))
In [8]: df
Out[8]:
A B C D
2013-01-010.469112-0.282863-1.509059-1.1356322013-01-021.212112-0.1732150.119209-1.0442362013-01-03-0.861849-2.104569-0.4949291.0718042013-01-040.721555-0.706771-1.0395750.2718602013-01-05-0.4249720.5670200.276232-1.0874012013-01-06-0.6736900.113648-1.4784270.524988
import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')
excel.Visible =True
_ =input("Press ENTER to quit:")
excel.Application.Quit()