您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“Python最常用的包有哪些”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Python最常用的包有哪些”吧!
numpy(數(shù)據(jù)處理和科學計算)
代碼示例:
arr = np.array([1, 2, 3, 4, 5]) print(arr)
pandas(數(shù)據(jù)處理和分析)
代碼示例:
data = {'name': ['John', 'Bob', 'Alice'], 'age': [20, 35, 25]} df = pd.DataFrame(data) print(df)
matplotlib(數(shù)據(jù)可視化)
代碼示例:
import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [4, 2, 7, 5, 9] plt.plot(x, y) plt.show()
scikit-learn(機器學習工具)
代碼示例:
from sklearn.linear_model import LinearRegression X = [[1, 4], [2, 5], [3, 6]] y = [8, 10, 12] model = LinearRegression().fit(X, y) print(model.predict([[4, 7]]))
tensorflow(深度學習框架)
代碼示例:
import tensorflow as tf x = tf.constant([1, 2, 3, 4]) y = tf.constant([5, 6, 7, 8]) z = tf.add(x, y) sess = tf.Session() print(sess.run(z))
keras(深度學習框架)
代碼示例:
from keras.models import Sequential from keras.layers import Dense model = Sequential() model.add(Dense(10, input_dim=5, activation='relu')) model.add(Dense(1, activation='sigmoid')) model.compile(loss='binary_crossentropy', optimizer='adam')
requests(HTTP 庫)
代碼示例:
import requests response = requests.get('https://www.baidu.com') print(response.text)
flask(Web 框架)
代碼示例:
from flask import Flask, render_template app = Flask(**name**) @app.route('/') def index(): return render_template('index.html') if **name** == '**main**': app.run(debug=True)
scrapy(網(wǎng)絡(luò)爬蟲框架)
代碼示例:
import scrapy class MySpider(scrapy.Spider): name = 'myspider' start_urls = ['http://quotes.toscrape.com'] def parse(self, response): for quote in response.css('div.quote'): yield {'text': quote.css('span.text::text').get(), 'author': quote.css('span small::text').get()}
beautifulsoup(HTML 解析器)
代碼示例:
from bs4 import BeautifulSoup html = '<html><head><title>這是標題</title></head><body><p>這是一個段落。</p ></body></html>' soup = BeautifulSoup(html, 'html.parser') print(soup.title.text)
selenium(Web 自動化測試)
代碼示例:
from selenium import webdriver driver = webdriver.Chrome() driver.get('https://www.baidu.com') search_box = driver.find_element_by_name('wd') search_box.send_keys('Python') search_box.submit()
ctypes(調(diào)用 C 語言庫)
代碼示例:
import ctypes lib = ctypes.cdll.LoadLibrary('libexample.so') lib.add(1, 2)
wxPython(GUI 開發(fā))
代碼示例:
import wx app = wx.App() frame = wx.Frame(None, title='Hello, wxPython!') frame.Show() app.MainLoop()
pillow(圖像處理)
代碼示例:
from PIL import Image im = Image.open('test.jpg') im.show()
openpyxl(處理 Excel 文件)
代碼示例:
import openpyxl wb = openpyxl.load_workbook('example.xlsx') sheet = wb['Sheet1'] cell = sheet['A1'] print(cell.value)
nltk(自然語言處理)
代碼示例:
import nltk sent = ‘This is a sentence.' tokens = nltk.word_tokenize(sent) print(tokens)
jieba(中文分詞)
代碼示例:
import jieba text = '我愛中文分詞' words = jieba.cut(text) for word in words: print(word)
re(正則表達式)
代碼示例:
import re text = 'The quick brown fox jumps over the lazy dog.' pattern = re.compile('fox') print(pattern.findall(text))
datetime(日期時間處理)
代碼示例:
import datetime dt = datetime.datetime.now() print(dt)
random(隨機數(shù)生成)
代碼示例:
import random print(random.randint(1, 10))
到此,相信大家對“Python最常用的包有哪些”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學習!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。