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()
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.6 except Exception as err: print(f'Other error occurred: {err}') # Python 3.6 else: 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.135632 2013-01-021.212112-0.1732150.119209-1.044236 2013-01-03-0.861849-2.104569-0.4949291.071804 2013-01-040.721555-0.706771-1.0395750.271860 2013-01-05-0.4249720.5670200.276232-1.087401 2013-01-06-0.6736900.113648-1.4784270.524988