Python酷库之旅-第三方库Pandas(137)

news2024/10/9 0:57:25

目录

一、用法精讲

616、pandas.plotting.andrews_curves方法

616-1、语法

616-2、参数

616-3、功能

616-4、返回值

616-5、说明

616-6、用法

616-6-1、数据准备

616-6-2、代码示例

616-6-3、结果输出

617、pandas.plotting.autocorrelation_plot方法

617-1、语法

617-2、参数

617-3、功能

617-4、返回值

617-5、说明

617-6、用法

617-6-1、数据准备

617-6-2、代码示例

617-6-3、结果输出

618、pandas.plotting.bootstrap_plot方法

618-1、语法

618-2、参数

618-3、功能

618-4、返回值

618-5、说明

618-6、用法

618-6-1、数据准备

618-6-2、代码示例

618-6-3、结果输出

619、pandas.plotting.boxplot方法

619-1、语法

619-2、参数

619-3、功能

619-4、返回值

619-5、说明

619-6、用法

619-6-1、数据准备

619-6-2、代码示例

619-6-3、结果输出

620、pandas.plotting.deregister_matplotlib_converters方法

620-1、语法

620-2、参数

620-3、功能

620-4、返回值

620-5、说明

620-6、用法

620-6-1、数据准备

620-6-2、代码示例

620-6-3、结果输出

二、推荐阅读

1、Python筑基之旅

2、Python函数之旅

3、Python算法之旅

4、Python魔法之旅

5、博客个人主页

一、用法精讲

616、pandas.plotting.andrews_curves方法
616-1、语法
# 616、pandas.plotting.andrews_curves方法
pandas.plotting.andrews_curves(frame, class_column, ax=None, samples=200, color=None, colormap=None, **kwargs)
Generate a matplotlib plot for visualizing clusters of multivariate data.
其他信息见下图

616-2、参数

616-2-1、frame(必须)DataFrame,表示输入的pandas DataFrame,包含需要绘制的多维数据。

616-2-2、class_column(必须)字符串或整数,指定用于分类的列名或列索引,该列中的每个类别将被绘制成不同颜色的曲线。

616-2-3、ax(可选,默认值为None)matplotlib.axes.Axes,如果提供,则将在指定的轴上绘图,如果没有提供,则会生成一个新的图形。

616-2-4、samples(可选,默认值为200)整数,用于生成安德鲁斯曲线的样本数量,样本越多,曲线越平滑,但计算时间也会增加。

616-2-5、color(可选,默认值为None)字符串或列表,用于指定各类别的颜色,如果指定为字符串,所有类别将使用相同颜色;如果是列表,则列表的长度应与类别数量相同。

616-2-6、colormap(可选,默认值为None)str or Colormap,指定一个colormap,这样可以自动为不同的类别分配颜色。

616-2-7、**kwargs(可选)其他关键字参数,其他参数,可以传递给matplotlib 的plot函数,控制线条样式、宽度等。

616-3、功能

        通过安德鲁斯曲线来展示数据中的不同类,每个类通过不同的曲线展示,从而让使用者能够直观地看到各类别在多维空间中的特征。

616-4、返回值

        返回一个matplotlib.figure.Figure对象,如果ax参数被指定,则会返回的是传入的Axes对象;如果没有,则返回生成的新的Figure对象。

616-5、说明

        无

616-6、用法
616-6-1、数据准备
616-6-2、代码示例
# 616、pandas.plotting.andrews_curves方法
import pandas as pd
import matplotlib.pyplot as plt
from pandas.plotting import andrews_curves
# 创建示例数据
data = {
    'class': ['A', 'A', 'B', 'B'],
    'feature1': [1, 2, 2, 3],
    'feature2': [3, 4, 1, 2]
}
df = pd.DataFrame(data)
# 绘制安德鲁斯曲线
andrews_curves(df, 'class')
plt.show()
616-6-3、结果输出
# 616、pandas.plotting.andrews_curves方法
见图1

图1:

 

617、pandas.plotting.autocorrelation_plot方法
617-1、语法
# 617、pandas.plotting.autocorrelation_plot方法
pandas.plotting.autocorrelation_plot(series, ax=None, **kwargs)
Autocorrelation plot for time series.

Parameters:
series
Series
The time series to visualize.

ax
Matplotlib axis object, optional
The matplotlib axis object to use.

**kwargs
Options to pass to matplotlib plotting method.

Returns:
matplotlib.axes.Axes.
617-2、参数

617-2-1、series(必须)series,输入的pandas Series,通常是时间序列数据,表示要分析的数据。

617-2-2、ax(可选,默认值为None)matplotlib.axes.Axes,如果提供,图形将绘制在指定的Axes上,如果未提供,将创建新的图形。

617-2-3、**kwargs(可选)其他关键字参数,可以传递给matplotlib的plot函数,以定制线条样式、颜色、标题等属性。

617-3、功能

        绘制自相关图,显示时间序列数据中数据点与不同滞后值之间的相关性,自相关图有助于识别时间序列的季节性和趋势性,可以用于模型的选择和调整,特别是在ARIMA等模型中。

617-4、返回值

        返回一个matplotlib.axes.Axes对象,如果指定了ax,则返回的是传入的Axes对象;如果没有指定,则返回创建的新的Axes对象。

617-5、说明

        无

617-6、用法
617-6-1、数据准备
617-6-2、代码示例
# 617、pandas.plotting.autocorrelation_plot方法
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# 创建示例时间序列数据
np.random.seed(0)
data = pd.Series(np.random.randn(100).cumsum())
# 绘制自相关图
pd.plotting.autocorrelation_plot(data)
plt.show()
617-6-3、结果输出
# 617、pandas.plotting.autocorrelation_plot方法
见图2

图2:

 

618、pandas.plotting.bootstrap_plot方法
618-1、语法
# 618、pandas.plotting.bootstrap_plot方法
pandas.plotting.bootstrap_plot(series, fig=None, size=50, samples=500, **kwds)
Bootstrap plot on mean, median and mid-range statistics.

The bootstrap plot is used to estimate the uncertainty of a statistic by relying on random sampling with replacement [1]. This function will generate bootstrapping plots for mean, median and mid-range statistics for the given number of samples of the given size.

[1]
“Bootstrapping (statistics)” in https://en.wikipedia.org/wiki/Bootstrapping_%28statistics%29

Parameters:
series
pandas.Series
Series from where to get the samplings for the bootstrapping.

fig
matplotlib.figure.Figure, default None
If given, it will use the fig reference for plotting instead of creating a new one with default parameters.

size
int, default 50
Number of data points to consider during each sampling. It must be less than or equal to the length of the series.

samples
int, default 500
Number of times the bootstrap procedure is performed.

**kwds
Options to pass to matplotlib plotting method.

Returns:
matplotlib.figure.Figure
Matplotlib figure.
618-2、参数

618-2-1、series(必须)series,表示输入的pandas Series,要进行自助法抽样的数据。

618-2-2、fig(可选,默认值为None)matplotlib.figure.Figure,如果提供,将在指定的图表上绘制;如果没有提供,将生成一个新的图表。

618-2-3、size(可选,默认值为50)整数,每次抽样的样本大小,即每次随机选择的观测值数量。

618-2-4、samples(可选,默认值为500)整数,自助法抽样的次数,表示要生成多少个样本。

618-2-5、**kwds(可选)其他关键字参数,可以传递给matplotlib的绘图函数以定制图表样式,如颜色、线型等。

618-3、功能

        展示通过自助法生成的样本的分布,可以用来理解原始数据的估计值的稳健性和不确定性,通过可视化多个样本的统计量(例如均值),用户可以获取对该统计量的置信区间的直观理解。

618-4、返回值

        返回一个matplotlib.axes.Axes对象,如果指定了fig,则返回的是该图表对象;如果没有指定,则返回创建的新图表对象。

618-5、说明

        无

618-6、用法
618-6-1、数据准备
618-6-2、代码示例
# 618、pandas.plotting.bootstrap_plot方法
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# 创建示例数据
np.random.seed(0)
data = pd.Series(np.random.randn(100).cumsum())
# 绘制自助法置信区间图
pd.plotting.bootstrap_plot(data, size=30, samples=200)
plt.title("Bootstrap Plot")
plt.xlabel("Sample Number")
plt.ylabel("Value")
plt.show()
618-6-3、结果输出
# 618、pandas.plotting.bootstrap_plot方法
见图3

图3:

 

619、pandas.plotting.boxplot方法
619-1、语法
# 619、pandas.plotting.boxplot方法
pandas.plotting.boxplot(data, column=None, by=None, ax=None, fontsize=None, rot=0, grid=True, figsize=None, layout=None, return_type=None, **kwargs)
Make a box plot from DataFrame columns.

Make a box-and-whisker plot from DataFrame columns, optionally grouped by some other columns. A box plot is a method for graphically depicting groups of numerical data through their quartiles. The box extends from the Q1 to Q3 quartile values of the data, with a line at the median (Q2). The whiskers extend from the edges of box to show the range of the data. By default, they extend no more than 1.5 * IQR (IQR = Q3 - Q1) from the edges of the box, ending at the farthest data point within that interval. Outliers are plotted as separate dots.

For further details see Wikipedia’s entry for boxplot.

Parameters:
dataDataFrame
The data to visualize.

columnstr or list of str, optional
Column name or list of names, or vector. Can be any valid input to pandas.DataFrame.groupby().

bystr or array-like, optional
Column in the DataFrame to pandas.DataFrame.groupby(). One box-plot will be done per value of columns in by.

axobject of class matplotlib.axes.Axes, optional
The matplotlib axes to be used by boxplot.

fontsizefloat or str
Tick label font size in points or as a string (e.g., large).

rotfloat, default 0
The rotation angle of labels (in degrees) with respect to the screen coordinate system.

gridbool, default True
Setting this to True will show the grid.

figsizeA tuple (width, height) in inches
The size of the figure to create in matplotlib.

layouttuple (rows, columns), optional
For example, (3, 5) will display the subplots using 3 rows and 5 columns, starting from the top-left.

return_type{‘axes’, ‘dict’, ‘both’} or None, default ‘axes’
The kind of object to return. The default is axes.

‘axes’ returns the matplotlib axes the boxplot is drawn on.

‘dict’ returns a dictionary whose values are the matplotlib Lines of the boxplot.

‘both’ returns a namedtuple with the axes and dict.

when grouping with by, a Series mapping columns to return_type is returned.

If return_type is None, a NumPy array of axes with the same shape as layout is returned.

**kwargs
All other plotting keyword arguments to be passed to matplotlib.pyplot.boxplot().

Returns:
result
See Notes.
619-2、参数

619-2-1、data(必须)DataFrame或Series,表示输入的数据集,包含要绘制箱线图的数据。

619-2-2、column(可选,默认值为None)字符串或字符串列表,指定要使用的列名,如果未指定且数据为DataFrame,则默认绘制所有数值型列。

619-2-3、by(可选,默认值为None)字符串或字符串列表,按指定的列进行分组,箱线图将绘制每个组的分布。

619-2-4、ax(可选,默认值为None)matplotlib.axes.Axes,如果提供,将在指定的坐标轴上绘制图形;如果未提供,将生成新的坐标轴。

619-2-5、fontsize(可选,默认值为None)整数或浮点数,用于设置轴标签和标题的字体大小。

619-2-6、rot(可选,默认值为0)整数,设置x轴刻度标签的旋转角度,以便于阅读。

619-2-7、grid(可选,默认值为True)布尔值,指定是否在图形上添加网格线。

619-2-8、figsize(可选,默认值为None)元组,设置图形的宽和高,格式为(width, height)。

619-2-9、layout(可选,默认值为None)元组,指定子图的布局,格式为(rows, columns)。

619-2-10、return_type(可选,默认值为None)字符串,如果设置为'axes',则返回绘制的坐标轴对象;如果设置为'data',则返回数据源。

619-2-11、**kwargs(可选)其他关键字参数,可以传递给matplotlib的绘图函数以定制图表样式,如颜色、边框等。

619-3、功能

        用于绘制箱线图(Box Plot),主要功能包括:

  • 可视化数据的分布情况,通过箱体展示数据的四分位数。
  • 显示异常值,通常在箱体外的点。
  • 通过分组绘制,比较不同组间数据的分布差异。
619-4、返回值

        返回一个matplotlib.axes.Axes对象(如果指定了ax)或生成的新轴对象,用户可以利用这个对象进行进一步的自定义和操作。

619-5、说明

        无

619-6、用法
619-6-1、数据准备
619-6-2、代码示例
# 619、pandas.plotting.boxplot方法
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# 创建示例数据
np.random.seed(0)
data = pd.DataFrame({
    'A': np.random.normal(size=100),
    'B': np.random.normal(loc=1, size=100),
    'C': np.random.normal(loc=2, size=100),
    'Category': ['Group1'] * 50 + ['Group2'] * 50
})
# 绘制箱线图
data.boxplot(column=['A', 'B', 'C'], by='Category', grid=True, figsize=(10, 6))
plt.title('Boxplot by Category')
plt.suptitle('')  # 去掉默认的超级标题
plt.xlabel('Category')
plt.ylabel('Values')
plt.show()
619-6-3、结果输出
# 619、pandas.plotting.boxplot方法
见图4

图4:

 

620、pandas.plotting.deregister_matplotlib_converters方法
620-1、语法
# 620、pandas.plotting.deregister_matplotlib_converters方法
pandas.plotting.deregister_matplotlib_converters()
Remove pandas formatters and converters.

Removes the custom converters added by register(). This attempts to set the state of the registry back to the state before pandas registered its own units. Converters for pandas’ own types like Timestamp and Period are removed completely. Converters for types pandas overwrites, like datetime.datetime, are restored to their original value.
620-2、参数

        无

620-3、功能
  • 解除自动转换:当使用pandas对时间序列数据进行绘图时,pandas默认会注册一些时间序列的转换器到matplotlib,以便处理datetime类型的数据。调用此函数后,pandas将不再注册这些时间序列转换器,可能会影响数据的显示和处理。
  • 提高性能:如果在某些情况下你知道不会使用时间序列数据,解除转换器可能会提高绘图的性能。
620-4、返回值

        该函数没有返回值,执行时只是确保不再将pandas的时间序列转换器注册到matplotlib的环境中。

620-5、说明

        如果你在绘图中使用了非时间序列数据,且希望改善绘图性能或避免不必要的转换,也许可以在特定场景中使用此函数。

620-6、用法
620-6-1、数据准备
620-6-2、代码示例
# 620、pandas.plotting.deregister_matplotlib_converters方法
import pandas as pd
import matplotlib.pyplot as plt
from pandas.plotting import deregister_matplotlib_converters
# 解除时间序列转换器的注册
deregister_matplotlib_converters()
# 创建一个简单的时间序列数据
date_rng = pd.date_range(start='2024-01-01', end='2024-01-10', freq='D')
data = pd.DataFrame(date_rng, columns=['date'])
data['data'] = pd.Series(range(1, len(data) + 1))
# 设置日期为索引
data.set_index('date', inplace=True)
# 绘图
plt.figure(figsize=(10, 5))
plt.plot(data.index, data['data'])
plt.title('Sample Plot without Time Series Converter')
plt.xlabel('Date')
plt.ylabel('Value')
plt.grid()
# 设置X轴标签倾斜45°
plt.xticks(rotation=30)
# 显示图表
plt.tight_layout()  # 调整布局以适应标签
plt.show()
620-6-3、结果输出
# 620、pandas.plotting.deregister_matplotlib_converters方法
见图5

图5:

 

二、推荐阅读

1、Python筑基之旅
2、Python函数之旅
3、Python算法之旅
4、Python魔法之旅
5、博客个人主页

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2197623.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

机器学习篇-day03-线性回归-正规方程与梯度下降-模型评估-正则化解决模型拟合问题

一. 线性回归简介 定义 线性回归(Linear regression)是利用 回归方程(函数) 对 一个或多个自变量(特征值)和因变量(目标值)之间 关系进行建模的一种分析方式。 回归方程(函数) 一元线性回归: y kx b > wx b k: 斜率, 在机器学习中叫 权重(weight), 简称: w b: 截距, 在机…

Linux驱动学习——内核编译

1、从官网下载适合板子的Linux内核版本 选择什么版本的内核需要根据所使用的硬件平台而定,最好使用硬件厂商推荐使用的版本 https://www.kernel.org/pub/linux/kernel/ 2、将压缩包复制到Ubuntu内进行解压 sudo tar -xvf linux-2.6.32.2-mini2440-20150709.tgz 然…

【C++ 11】nullptr 空指针

文章目录 【 0. 问题背景 】0.1 野指针和悬空指针0.2 传统空指针 NULL0.3 传统空指针的局限性 【 1. 基本用法 】【 2. nullptr 的应用 】2.1 nullptr 解决 NULL 的遗留BUG2.2 简单实例 【 0. 问题背景 】 0.1 野指针和悬空指针 总结 野指针悬空指针产生原因指针变量未被初始…

绕过中间商,不用 input 标签也能搞定文件选择

💰 点进来就是赚到知识点!本文带你用 JS 实现文件选择功能,点赞、收藏、评论更能促进消化吸收! 🚀 想解锁更多 Web 文件系统技能吗?快来订阅专栏「Web 玩转文件操作」! 📣 我是 Jax,…

【机器学习】线性回归算法简介 及 数学实现方法

线性回归 简介 利用 回归方程(函数) 对 一个或多个自变量(特征值)和因变量(目标值)之间 关系进行建模的一种分析方式。 数学公式: ℎ_(w) w_1x_1 w_2x_2 w_3x_3 … b w^Txb 概念 ​ 利用回归方程(函数) 对 一个或多个自变量(特征值)和因变量(目标值)之间 关…

易基因: cfMeDIP-seq揭示cfDNA甲基化高效区分原发性和转移性前列腺|Nat Commun

大家好,这里是专注表观组学十余年,领跑多组学科研服务的易基因。 前列腺癌(Prostate cancer,PCa)是男性中第二常见的恶性肿瘤,也是全球癌症相关死亡的第三大原因。虽然大多数原发性前列腺癌可以治愈&#…

交易所开发:构建安全、高效、可靠的数字资产交易平台

数字资产交易平台是加密市场中连接用户与数字货币的重要枢纽。开发一个安全、高效、可靠的交易所,不仅需要综合考虑技术架构、安全策略、用户体验等方面,还需严格遵循法规要求以确保合规性。本文总结了交易所开发的关键要素,包括其类型、核心…

振弦式土体沉降计有哪些功能特点

振弦式土体沉降计是一种广泛应用于土木工程领域的测量仪器,用于监测土石坝、边坡、地基等构筑物的沉降变形。以下是南京峟思给大家介绍的振弦式土体沉降计的主要优点: 高精度测量: 振弦式土体沉降计采用先-进的感应技术,能够精确地…

一个月学会Java 第5天 控制结构

Day5 控制结构 这么叫可能有些就算有基础的人也看不懂,其实就是if-else、switch-case、for、while、do-while这几个,没基础的听到了这个也不要慌张,这几个是程序的基础,多多训练就好 第一章 顺序结构 这章其实没有什么好讲的&…

Python 工具库每日推荐【openpyxl 】

文章目录 引言Python Excel 处理库的重要性今日推荐:openpyxl 工具库主要功能:使用场景:安装与配置快速上手示例代码代码解释实际应用案例案例:自动生成月度销售报告案例分析高级特性条件格式数据验证扩展阅读与资源优缺点分析优点:缺点:总结【 已更新完 TypeScript 设计…

2024 Mysql基础与进阶操作系列之MySQL触发器详解(20)作者——LJS[你个小黑子这都还学不会嘛?你是真爱粉嘛?真是的 ~;以后请别侮辱我家鸽鸽]

欢迎各位彦祖与热巴畅游本人专栏与博客 你的三连是我最大的动力 以下图片仅代表专栏特色 [点击箭头指向的专栏名即可闪现] 专栏跑道一 ➡️ MYSQL REDIS Advance operation 专栏跑道二➡️ 24 Network Security -LJS ​ ​ ​ 专栏跑道三 ➡️HCIP;H3C-SE;CCIP——…

不容错过的10款文件加密软件,2024顶尖办公文件加密软件分享

随着数据隐私和信息安全越来越受到重视,文件加密已经成为保护个人和企业机密信息的必备工具。无论是敏感的个人文件、财务报表、商业机密,还是政府机密信息,都需要高效的加密工具来确保信息安全不被未经授权的人访问。在2024年,我…

盘点2024年4款打工人都在用的PDF软件。

PDF 软件在现代的办公或者是学习当中的应用非常广泛,已经成了很多人的必备工具。因为PDF 文件具有跨设备、跨系统的优势,所以在很多设备上都可以打开浏览。如果有了PDF 编辑软件,查看,编辑,分享也会变得更加方便简单&a…

web自动化测试基础(从配置环境到自动化实现登录测试用例的执行,vscode如何导入自己的python包)

接下来的一段时间里我会和大家分享自动化测试相关的一些知识希望大家可以多多支持,一起进步。 一、环境的配置 前提安装好了python解释器并配好了环境,并安装好了VScode 下载的浏览器和浏览器驱动需要一样的版本号(只看大版本)。 1、安装浏览器 Chro…

回到原点再出发

原文What Goes Around Comes Around作者Michael Stonebraker & Joseph M. Hellerstein其他译文https://zhuanlan.zhihu.com/p/111322429 1. 摘要 本文总结了近35年来的数据模型方案,分成9个不同的时代,讨论了每个时代的方案。我们指出,…

Vue3入门 - provide和inject组合使用

在Vue3中&#xff0c;provide和inject是用于实现依赖注入的一对API。它们允许在组件树中传递和接收数据&#xff0c;而不需要通过每一层显式地传递props。在<script setup>语法中&#xff0c;provide可以用来提供一个值&#xff0c;而inject可以用来接收一个已经提供的值…

RNN(循环神经网络)简介及应用

一、引言 在深度学习领域&#xff0c;神经网络被广泛应用于各种任务&#xff0c;从图像识别到语音合成。但对于序列数据处理的任务&#xff0c;如自然语言处理&#xff08;NLP&#xff09;、语音识别或时间序列预测等&#xff0c;传统的前馈神经网络&#xff08;Feedforward N…

启明智显工业级HMI芯片Model4功耗特性分享

Model4工业级MPU是国产自主面向工业应用的RISC-V架构的应用级芯片&#xff0c;内置玄铁64bit RISC-V CPU C906&#xff0c;主频高达600MHz&#xff0c;算力约1380DMIPS。支持RTOS、linux系统&#xff0c;支持LVGL工具开发UI&#xff1b; Model4系列工业级MPU具有极强的屏显、多…

每日OJ题_牛客_分组_枚举+二分_C++_Java

目录 牛客_分组_枚举二分 题目解析 C代码 Java代码 牛客_分组_枚举二分 分组 (nowcoder.com) 描述&#xff1a; dd当上了宣传委员&#xff0c;开始组织迎新晚会&#xff0c;已知班里有nnn个同学&#xff0c;每个同学有且仅有一个擅长的声部&#xff0c;把同学们分…

计算机组成原理:物理层 —— 编码与调制

文章目录 基本概念编码&#xff08;基带调制&#xff09;调制编码与调制码元 编码方式双极性不归零编码双极性归零编码曼彻斯特编码差分曼彻斯特编码优缺点 调制方法基本的带通调制方法调频 FM调幅 AM调相 PM 混合调制方法正交振幅调制 QAM-16 基本概念 编码&#xff08;基带调…