以下文章来源于读芯术 ,作者读芯术
专注年轻人的AI学习与发展平台
pip install beautifulsoup4
#!/usr/bin/python3 # Anchor extraction from html document from bs4 import BeautifulSoup from urllib.request import urlopen with urlopen('LINK') as response: soup = BeautifulSoup(response, 'html.parser') for anchor in soup.find_all('a'): print(anchor.get('href', '/'))
pip install scrapy
import scrapy class Spider(scrapy.Spider): name = 'NAME' start_urls = ['LINK'] def parse(self, response): for title in response.css('.post-header>h2'): yield {'title': title.css('a ::text').get()} for next_page in response.css('a.next-posts-link'): yield response.follow(next_page, self.parse
pip install pandas
pip install pyod
$ pip install numpy
import numpy as np x = np.array([1, 2, 3]) print(x) y = np.arange(10) print(y)
output - [1 2 3] [0 1 2 3 4 5 6 7 8 9]
a = np.array([1, 2, 3, 6]) b = np.linspace(0, 2, 4) c = a - b print(c) print(a**2)
output - [1. 1.33333333 1.66666667 4. ] [ 1 4 9 36]
pip install -U spacy python -m spacy download en
$ pip install matplotlib
%matplotlib inline import matplotlib.pyplot as plt from numpy.random import normal x = normal(size=100) plt.hist(x, bins=20) plt.show()
from matplotlib import cm from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.gca(projection='3d') X = np.arange(-10, 10, 0.1) Y = np.arange(-10, 10, 0.1) X, Y = np.meshgrid(X, Y) R = np.sqrt(X**2 + Y**2) Z = np.sin(R) surf = ax.plot_surface(X, Y, Z, rstride=1,cstride=1, cmap=cm.coolwarm) plt.show()
pip install seaborn
import seaborn as sns sns.set() tips =sns.load_dataset("tips") sns.relplot(x="total_bill",y="tip", col="time", hue="smoker",style="smoker", size="size", data=tips);
import seaborn as sns sns.catplot(x="day",y="total_bill", hue="smoker", kind="violin",split=True, data=tips);
pip install bokeh
pip install lime
pip install madmom
pip install pyAudioAnalysis
pip3 install opencv-python
pip install -U scikit-learn
pip install Pillow
pip install psycopg2
pip install SQLAlchemy
from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "HelloWorld!" if __name__ == "__main__": app.run()