Python数据分析——NumPy、Matplotlib、Pandas
·
NumPy实践
题目:如何得到昨天,今天,明天的的日期
知识点:【时间日期】
- (提示: np.datetime64, np.timedelta64)
代码:
import numpy as np
yesterday = np.datetime64('today', 'D') - np.timedelta64(1, 'D')
today = np.datetime64('today', 'D')
tomorrow = np.datetime64('today', 'D') + np.timedelta64(1, 'D')
print("Yesterday is " + str(yesterday))
print("Today is " + str(today))
print("Tomorrow is "+ str(tomorrow))
运行结果:

Matplotlib实践
题目:分别用一组长方形柱和填充面积的方式模仿画出下图,函数 y = -1 * (x - 2) * (x - 8) +10 在区间[2,9]的积分面积
代码:
# 分别用一组长方形柱和填充面积的方式模仿画出下图,函数 y = -1 * (x - 2) * (x - 8) +10 在区间[2,9]的积分面积
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
import numpy as np
x = np.linspace(0, 10)
y = -1 * (x - 2) * (x - 8) + 10
fig, ax = plt.subplots(2, 1, figsize=(6, 8))
ax[0].plot(x, y, color='red')
ax[1].plot(x, y, color='red')
ax[0].set_ylim(0)
ax[1].set_ylim(0)
x_bar = np.linspace(2, 9)
y_bar = -1 * (x_bar - 2) * (x_bar - 8) + 10
ax[0].bar(x_bar, y_bar, width=0.1, color='lightgray')
ax[1].bar(x_bar, y_bar, width=0.15, color='lightblue')
plt.show()
运行结果:

Pandas实践
题目:更新矩阵

代码:
import numpy as np
A = np.arange(1, 10).reshape(3, -1)
B = A*(1/A).sum(1).reshape(-1, 1)
print(B)
运行结果:

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐


所有评论(0)