最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python最常用的20 個包總結

 更新時間:2023年04月12日 09:52:07   作者:不吃西紅柿丶  
這篇文章主要介紹了Python最常用的20 個包總結,在平時使用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)絡爬蟲框架)

代碼示例:

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最常用的20 個包總結的文章就介紹到這了,更多相關Python常用包內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

大洼县| 克什克腾旗| 大厂| 扎囊县| 定襄县| 亳州市| 泸州市| 呈贡县| 城市| 蒲江县| 江川县| 仁怀市| 东兰县| 遂溪县| 东至县| 广灵县| 南华县| 格尔木市| 阜平县| 凤山县| 恩施市| 乐安县| 讷河市| 无锡市| 马边| 济阳县| 龙胜| 桐梓县| 慈溪市| 蒙自县| 龙江县| 德保县| 龙胜| 额济纳旗| 双桥区| 磴口县| 平江县| 玛曲县| 平昌县| 抚远县| 东海县|