欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python最常用的20 個(gè)包總結(jié)

 更新時(shí)間:2023年04月12日 09:52:07   作者:不吃西紅柿丶  
這篇文章主要介紹了Python最常用的20 個(gè)包總結(jié),在平時(shí)使用Python的過程中,需要用到很多有用的包,今天就來盤點(diǎn)一下常用的包,需要的朋友可以參考下

numpy(數(shù)據(jù)處理和科學(xué)計(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(機(jī)器學(xué)習(xí)工具)

代碼示例:

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(深度學(xué)習(xí)框架)

代碼示例:

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(深度學(xué)習(xí)框架)

代碼示例:

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>這是標(biāo)題</title></head><body><p>這是一個(gè)段落。</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(正則表達(dá)式)

代碼示例:

import re

text = 'The quick brown fox jumps over the lazy dog.'
pattern = re.compile('fox')
print(pattern.findall(text))

datetime(日期時(shí)間處理)

代碼示例:

import datetime

dt = datetime.datetime.now()
print(dt)

random(隨機(jī)數(shù)生成)

代碼示例:

import random
print(random.randint(1, 10))

到此這篇關(guān)于Python最常用的20 個(gè)包總結(jié)的文章就介紹到這了,更多相關(guān)Python常用包內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python實(shí)現(xiàn)排序方法常見的四種

    Python實(shí)現(xiàn)排序方法常見的四種

    本文給大家分享python四種常見排序方法,每種方法通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧
    2021-07-07
  • Python unittest如何生成HTMLTestRunner模塊

    Python unittest如何生成HTMLTestRunner模塊

    這篇文章主要介紹了Python unittest如何生成HTMLTestRunner模塊,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • Python中的元組(Tuple)操作實(shí)例詳解

    Python中的元組(Tuple)操作實(shí)例詳解

    Python?元組和列表很像,也是一個(gè)包含多個(gè)元素的集合,下面這篇文章主要給大家介紹了關(guān)于Python中元組(Tuple)操作的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-02-02
  • 利用Pygame繪制圓環(huán)的示例代碼

    利用Pygame繪制圓環(huán)的示例代碼

    這篇文章主要介紹了利用Python中的Pygame模塊繪制一個(gè)彩色的圓環(huán),文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)Pygame有一定幫助,需要的可以參考一下
    2022-01-01
  • python連接MySQL數(shù)據(jù)庫實(shí)例分析

    python連接MySQL數(shù)據(jù)庫實(shí)例分析

    這篇文章主要介紹了python連接MySQL數(shù)據(jù)庫,實(shí)例分析了Python操作MySQL的相關(guān)技巧,需要的朋友可以參考下
    2015-05-05
  • Python+radar實(shí)現(xiàn)隨機(jī)日期時(shí)間的生成

    Python+radar實(shí)現(xiàn)隨機(jī)日期時(shí)間的生成

    Python有廣泛豐富的第三方庫,在沒有特殊定制下,避免了重復(fù)造輪子。本文將利用radar庫實(shí)現(xiàn)生成隨機(jī)的日期或時(shí)間,文中的示例代碼講解詳細(xì),感興趣的可以了解一下
    2022-05-05
  • Python實(shí)現(xiàn)提高運(yùn)行速度的技巧分享

    Python實(shí)現(xiàn)提高運(yùn)行速度的技巧分享

    這篇文章主要為大家詳細(xì)介紹了Python實(shí)現(xiàn)提高運(yùn)行速度的相關(guān)技巧,文中的示例代碼講解詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴可以跟隨小編一起了解一下
    2023-06-06
  • Python實(shí)現(xiàn)的多線程端口掃描工具分享

    Python實(shí)現(xiàn)的多線程端口掃描工具分享

    這篇文章主要介紹了Python實(shí)現(xiàn)的多線程端口掃描工具分享,工具實(shí)現(xiàn)了掃單IP和掃IP段功能,本文給出運(yùn)行效果和實(shí)現(xiàn)源碼,需要的朋友可以參考下
    2015-01-01
  • Python利用matplotlib畫出漂亮的分析圖表

    Python利用matplotlib畫出漂亮的分析圖表

    這篇文章主要介紹了Python利用matplotlib畫出漂亮的分析圖表,文章首先引入數(shù)據(jù)集展開詳情,需要的朋友可以參考一下
    2022-07-07
  • python3實(shí)現(xiàn)帶多張圖片、附件的郵件發(fā)送

    python3實(shí)現(xiàn)帶多張圖片、附件的郵件發(fā)送

    這篇文章主要為大家詳細(xì)介紹了python3實(shí)現(xiàn)帶多張圖片、附件的郵件發(fā)送,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-08-08

最新評論