代码示例:
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 = '这是标题 这是一个段落。
'
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))