赞
踩
【python零基础入门小白】博主存在的意义:旨在帮助各位学习Python的小伙伴获得更高速更效率的学习收获。
这篇文章主要介绍了Python最常用的20 个包总结,在平时使用Python的过程中,需要用到很多有用的包,今天就来盘点一下常用的包,需要的朋友可以参考下
代码示例:
arr = np.array([1, 2, 3, 4, 5])
print(arr)
data = {'name': ['John', 'Bob', 'Alice'], 'age': [20, 35, 25]}
df = pd.DataFrame(data)
print(df)
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [4, 2, 7, 5, 9]
plt.plot(x, y)
plt.show()
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]]))
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))
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')
import requests
response = requests.get('https://www.baidu.com')
print(response.text)
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)
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()}
from bs4 import BeautifulSoup
html = '<html><head><title>这是标题</title></head><body><p>这是一个段落。</p ></body></html>'
soup = BeautifulSoup(html, 'html.parser')
print(soup.title.text)
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()
import ctypes
lib = ctypes.cdll.LoadLibrary('libexample.so')
lib.add(1, 2)
import wx
app = wx.App()
frame = wx.Frame(None, title='Hello, wxPython!')
frame.Show()
app.MainLoop()
from PIL import Image
im = Image.open('test.jpg')
im.show()
import openpyxl
wb = openpyxl.load_workbook('example.xlsx')
sheet = wb['Sheet1']
cell = sheet['A1']
print(cell.value)
import nltk
sent = ‘This is a sentence.'
tokens = nltk.word_tokenize(sent)
print(tokens)
import jieba
text = '我爱中文分词'
words = jieba.cut(text)
for word in words:
print(word)
import re
text = 'The quick brown fox jumps over the lazy dog.'
pattern = re.compile('fox')
print(pattern.findall(text))
import datetime
dt = datetime.datetime.now()
print(dt)
import random
print(random.randint(1, 10))
到此这篇关于Python最常用的20 个包总结的文章就介绍到这了。希望大家以后持续关注博主~
学好 Python 不论是就业还是做副业赚钱都不错,但要学会 Python 还是要有一个学习规划。最后大家分享一份全套的 Python 学习资料,给那些想学习 Python 的小伙伴们一点帮助!
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/632643
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。