盘点8个数据分析相关的Python库(实例+代码)
导读:Python中常会用到一些专门的库,如NumPy、SciPy、Pandas和Matplotlib。数据处理常用到NumPy、SciPy和Pandas,数据分析常用到Pandas和Scikit-Learn,数据可视化常用到Matplotlib,而对大规模数据进行分布式挖掘时则可以使用Pyspark来调用Spark集群的资源。
作者:刘鹏 高中强 王一凡 等
import numpy as np
a = np.array(6)
a.dtype
output: dtype('int64')
ndarray.ndim:秩,即轴的数量或维度的数量 ndarray.shape:数组的维度,如果存的是矩阵,如n×m矩阵则输出为n行m列 ndarray.size:数组元素的总个数,相当于.shape中n×m的值 ndarray.dtype:ndarray对象的元素类型 ndarray.itemsize:ndarray对象中每个元素的大小,以字节为单位 ndarray.flags:ndarray对象的内存信息 ndarray.real:ndarray元素的实部 ndarray.imag:ndarray元素的虚部 ndarray.data:包含实际数组元素的缓冲区,由于一般通过数组的索引获取元素,所以通常不需要使用这个属性
# 引入所需要的库
import numpy as np
import matplotlib.pyplot as plt
# 使用 polyld() 函数创建多项式 func=1x3+2x2+3x+4
func = np.poly1d(np.array([1,2,3,4]).astype(f?loat))
# 使用 NumPy 的 linspace() 函数在 -10 和 10 之间产生 30 个均匀分布的值,作为函数 x 轴的取值
x = np.linspace(-10, 10 , 30)
# 将 x 的值代入 func() 函数,计算得到 y 值
y=func(x)
# 调用 pyplot 的 plot 函数 (),绘制函数图像
plt.plot(x, y)
# 使用 xlable() 函数添加 x 轴标签
plt.xlabel('x')
# 使用 ylabel() 函数添加 y 轴标签
plt.ylabel('y(x)')
# 调用 show() 函数显示函数图像
plt.show()
# 导入相关包
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import f?igure
f?igure(num=None, f?igsize=(12, 8), dpi=80, facecolor='w', edgecolor='k')
# 计算正弦和余弦曲线上点的 x 和 y 坐标
x = np.arange(0, 3 * np.pi, 0.1)
y_sin = np.sin(x)
y_cos = np.cos(x)
# subplot的3个参数,2、1、1 ,表示绘制2行1列图像中的第一个子图
plt.subplot(2, 1, 1)# 绘制第一个子图
# 绘制第一个图像
plt.plot(x, y_sin)
plt.title('Sin')
plt.subplot(2, 1, 2)# 绘制2行1 列图像中的第二个子图
plt.plot(x, y_cos)
plt.title('Cos')
plt.show()# 显示图像
干货直达👇
手把手教你获取、编译和调试Flink的源代码
关键词
数组
对象
函数
图像
元素
最新评论
推荐文章
作者最新文章
你可能感兴趣的文章
Copyright Disclaimer: The copyright of contents (including texts, images, videos and audios) posted above belong to the User who shared or the third-party website which the User shared from. If you found your copyright have been infringed, please send a DMCA takedown notice to [email protected]. For more detail of the source, please click on the button "Read Original Post" below. For other communications, please send to [email protected].
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。