《Python数据分析技术栈》第03章 03 可视化各级数据(Visualizing various levels of data)

03 可视化各级数据(Visualizing various levels of data)

《Python数据分析技术栈》第03章 03 可视化各级数据(Visualizing various levels of data)

Whenever you need to analyze data, first understand if the data is structured or unstructured. If the data is unstructured, convert it to a structured form with rows and columns, which makes it easier for further analysis using libraries like Pandas. Once you have data in this format, categorize each of the features or columns into the four levels of data and perform your analysis accordingly.

无论何时需要分析数据,首先要了解数据是结构化的还是非结构化的。如果是非结构化数据,则应将其转换为具有行和列的结构化形式,这样更便于使用 Pandas 等库进行进一步分析。有了这种格式的数据后,将每个特征或列归类到数据的四个层次,然后进行相应的分析。

Note that in this chapter, we only aim to understand how to categorize the variables in a dataset and identify the operations and plots that would apply for each category. The actual code that needs to be written to visualize the data is explained in Chapter 7.

请注意,在本章中,我们只想了解如何对数据集中的变量进行分类,并确定适用于每个类别的操作和绘图。为实现数据可视化而需要编写的实际代码将在第 7 章中讲解。

We look at how to classify the features and perform various operations using the famous Titanic dataset. The dataset can be imported from here: https://github.com/DataRepo2019/Data-files/blob/master/titanic.csv

我们将使用著名的泰坦尼克号数据集来研究如何对特征进行分类并执行各种操作。数据集可从此处导入: https://github.com/DataRepo2019/Data-files/blob/master/titanic.csv

Background information about the dataset: The RMS Titanic, a British passenger ship, sank on its maiden voyage from Southampton to New York on 15th April 1912, after it collided with an iceberg. Out of the 2,224 passengers, 1,500 died, making this event a tragedy of epic proportions. This dataset describes the survival status of the passengers and other details about them, including their class, name, age, and the number of relatives.

数据集背景信息: 1912 年 4 月 15 日,英国皇家泰坦尼克号客轮在从南安普顿到纽约的处女航中与冰山相撞沉没。在 2224 名乘客中,有 1500 人丧生,使这一事件成为史诗般的悲剧。该数据集描述了乘客的生还状况及其他详细信息,包括他们的等级、姓名、年龄和亲属人数。

在这里插入图片描述

The features in this dataset, classified according to the data level, are captured in Table 4-1.

表 4-1 根据数据级别对数据集中的特征进行了分类。

在这里插入图片描述

Let us now understand the rationale behind the classification of the features in this dataset.

现在,让我们来了解一下对该数据集中的特征进行分类的原理。

Nominal variables: Variables like “PassengerId”, “Survived”, “Name”, “Sex”, “Cabin”, and “Embarked” do not have any intrinsic ordering of their values. Note that some of these variables have numeric values, but these values are finite in number. We cannot perform an arithmetic operation on these values like addition, subtraction, multiplication, or division. One operation that is common with nominal variables is counting. A commonly used method in Pandas, value_counts (discussed in the next chapter), is used to determine the number of values per each unique category of the nominal variable. We can also find the mode (the most frequently occurring value). The bar graph is frequently used to visualize nominal data (pie charts can also be used), as shown in Figure 4-5.

名义变量: PassengerId"、“Survived”、“Name”、“Sex”、"Cabin "和 "Embarked "等变量的值没有内在顺序。需要注意的是,其中一些变量有数值,但这些数值的数量是有限的。我们无法对这些数值进行加、减、乘或除等算术运算。对名义变量常用的一种操作是计数。Pandas 中的一个常用方法 value_counts(将在下一章中讨论)用于确定标称变量中每个独特类别的值的数量。我们还可以找到模式(出现频率最高的值)。如图 4-5 所示,条形图常用于将名义数据可视化(也可以使用饼图)。

Ordinal variables: “Pclass” (or Passenger Class) is an ordinal variable since its values follow an order. A value of 1 is equivalent to first class, 2 is equivalent to the second class, and so on. These class values are indicative of socioeconomic status.

顺序变量: “Pclass”(或乘客等级)是一个顺序变量,因为它的值是有顺序的。数值 1 代表一等舱,2 代表二等舱,以此类推。这些等级值表明了社会经济地位。

We can find out the median value and percentiles. We can also count the number of values in each category, calculate the mode, and use plots like bar graphs and pie charts, just as we did for nominal variables.

我们可以找出中位值和百分位数。我们还可以计算每个类别中的数值个数、计算模式,并使用条形图和饼图等图表,就像我们对名义变量所做的那样。

In Figure 4-6, we have used a pie chart for the ordinal variable “Pclass”

在图 4-6 中,我们使用饼图来表示序数变量 “Pclass”。

Ratio Data: The “Age” and “Fare” variables are examples of ratio data, with the value zero as a reference point. With this type of data, we can perform a wide range of mathematical operations. For example, we can add all the fares and divide it by the total number of passengers to find the mean. We can also find out the standard deviation. A histogram, as shown in Figure 4-7, can be used to visualize this kind of continuous data to understand the distribution.

比率数据: 年龄 "和 "票价 "变量是比率数据的例子,以零值为参考点。利用这类数据,我们可以进行多种数学运算。例如,我们可以将所有票价相加,然后除以乘客总数,得出平均值。我们还可以求出标准差。直方图(如图 4-7 所示)可用于直观显示这类连续数据,以了解其分布情况。

In the preceding plots, we looked at the graphs for plotting individual categorical or continuous variables. In the following section, we understand which graphs to use when we have more than one variable or a combination of variables belong to different scales or levels.

在前面的绘图中,我们了解了用于绘制单个分类变量或连续变量的图形。在下一节中,我们将了解当有多个变量或变量组合属于不同尺度或级别时,应该使用哪种图形。

绘制混合数据(Plotting mixed data)

In this section, we’ll consider three scenarios, each of which has two variables that may or may not belong to the same level and discuss which plot to use for each scenario (using the same Titanic dataset).

在本节中,我们将考虑三种情况,每种情况都有两个变量,这两个变量可能属于也可能不 属于同一级别,并讨论每种情况下应使用哪种曲线图(使用相同的泰坦尼克数据集)。

One categorical and one continuous variable: A box plot shows the distribution, symmetry, and outliers for a continuous variable. A box plot can also show the continuous variable against a categorical variable. In Figure 4-8, the distribution of ‘Age’ (a ratio variable) for each value of the nominal variable – ‘Survived’ (0 is the value for passengers who did not survive and 1 is the value for those who did).

一个分类变量和一个连续变量: 方框图显示连续变量的分布、对称性和异常值。方框图还可以显示连续变量与分类变量的对比情况。在图 4-8 中,“年龄”(比率变量)在名义变量 “存活”(0 代表未存活乘客的值,1 代表存活乘客的值)的每个值上的分布情况。

Both continuous variables: Scatter plots are used to depict the relationship between two continuous variables. In Figure 4-9, we plot two ratio variables, ‘Age’ and ‘Fare’, on the x and y axes to produce a scatter plot.

都是连续变量: 散点图用于描述两个连续变量之间的关系。在图 4-9 中,我们将两个比率变量 "年龄 "和 "票价 "分别绘制在 x 轴和 y 轴上,从而得到散点图。

Both categorical variables: Using a clustered bar chart (Figure 4-10), you can combine two categorical variables with the bars depicted side by side to represent every combination of values for the two variables.

两个分类变量: 使用聚类条形图(图 4-10),可以将两个分类变量结合在一起,并列的条形图代表了这两个变量的所有数值组合。

We can also use a stacked bar chart to plot two categorical variables. Consider the following stacked bar chart, shown in Figure 4-11, plotting two categorical variables –“Pclass” and “Survived”

我们还可以使用堆叠条形图来绘制两个分类变量。下面是图 4-11 所示的堆叠条形图,其中绘制了两个分类变量–"Pclass "和 “Survived”。

In summary, you can use a scatter plot for two continuous variables, a stacked or clustered bar chart for two categorical variables, and a box plot when you want to display a continuous variable across different values of a categorical variable.

总之,您可以对两个连续变量使用散点图,对两个分类变量使用堆叠条形图或聚类条形图,当您想在分类变量的不同值之间显示连续变量时使用盒状图。

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

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

相关文章

二叉树的直径(LeetCode 543)

文章目录 1.问题描述2.难度等级3.热门指数4.解题思路参考文献 1.问题描述 给你一棵二叉树的根节点,返回该树的直径 。 二叉树的 直径 是指树中任意两个节点之间最长路径的长度 。这条路径可能经过也可能不经过根节点 root 。 两节点之间路径的长度由它们之间边数…

CentOS Linux操作系统源码安装最新Redis版本,使用JSON数据类型踩入新坑

最近有空查阅了redis官网,发现redis数据类型不止Strings、Lists、Sets、Hashes、Sorted sets,还多了几种,决定先试用下JSON数据类型 1、安装Redis软件 JSON数据类型,对Redis版本有要求,需要大于4.0版本。下图是华为云…

开源项目介绍

浙大高飞课题组 微分平坦 微分平坦的思想是:一个全维度的状态空间可以被一组低维的精心挑选的输出平坦空间(flat-output space)的变量及其导数的代数组合的方式所表示。由此,轨迹规划就可以在这组精心挑选的变量的空间所进行。 …

【C++提高编程(二)】

一、STL初识 1.1、STL的诞生 长久以来,软件界一直希望建立一种可重复利用的东西 C的面向对象和泛型编程思想,目的就是复用性的提升 大多情况下,数据结构和算法都未能有一套标准,导致被迫从事大量重复工作 为了建立数据结构和算法的一套标…

一文详解 Berachain 测试网:全面介绍与教程,bitget wallet教程

什么是Berachain? Berachain(web3.bitget.com/zh-CN/assets/berachain-wallet)是一种尖端区块链技术,使用 Cosmos SDK 构建的 Layer-1,兼容以太坊虚拟机(EVM)。它基于一种独特的概念&#xff0c…

【AI】人工智能和图像编码(2)

传统图像编解码与智能图像编解码,都是要编码和解码,但还是有一些区别的。 相关相同点和要点描述如下: 一、区别 1.1 技术原理 传统图像编解码:主要依赖于固定的算法和标准,如JPEG、MPEG等,进行图像的压…

[晓理紫]每日论文分享(有中文摘要,源码或项目地址)--机器人相关、强化学习

专属领域论文订阅 VX 扫吗关注{晓理紫|小李子},每日更新论文,如感兴趣,请转发给有需要的同学,谢谢支持 分类: 大语言模型LLM视觉模型VLM扩散模型视觉导航具身智能,机器人强化学习开放词汇,检测分割 [晓理紫…

LeetCode、2542. 最大子序列的分数【中等,排序+小顶堆】

文章目录 前言LeetCode、2542. 最大子序列的分数【中等,排序小顶堆】题目及类型思路及代码实现 资料获取 前言 博主介绍:✌目前全网粉丝2W,csdn博客专家、Java领域优质创作者,博客之星、阿里云平台优质作者、专注于Java后端技术领…

2024最新AWVS/Acunetix Premium v24.1.24高级版漏洞扫描器Windows/Linux下载

前言 Acunetix Premium 是一种 Web 应用程序安全解决方案,用于管理多个网站、Web 应用程序和 API 的安全。集成功能允许您自动化 DevOps 和问题管理基础架构。 Acunetix Premium:全面的 Web 应用程序安全解决方案 Web 应用程序对于企业和组织与客户、合作…

算法练习-替换数字(思路+流程图+代码)

难度参考 难度:简单 分类:字符串 难度与分类由我所参与的培训课程提供,但需要注意的是,难度与分类仅供参考。以下内容均为个人笔记,旨在督促自己认真学习。 题目 给定一个字符串S,它包含小写字母和数字字符&#xff0…

设备巡检系统开发及部署

**凡尔码设备巡检系统**是一种低代码模块搭建设备管理系统平台;用户可通过平台开发好的组件像搭积木一般灵活搭建设备管理平台和无纸化应用场景。凡尔码平台功能组件:二维码管理、表单管理、流程管理、计划管理、权限管理、隐患管理、区域管理、记录管理…

数据结构之二叉树的性质与存储结构

数据结构之二叉树的性质与存储结构 1、二叉树的性质2、二叉树的存储结构 数据结构是程序设计的重要基础,它所讨论的内容和技术对从事软件项目的开发有重要作用。学习数据结构要达到的目标是学会从问题出发,分析和研究计算机加工的数据的特性,…

【趣味题-03】20240120猴子吃桃( 从大到小insert ,列表元素互减)

背景需求: 猴子摘桃的题目 解决: 猴子吃桃 倍数问题 作者:阿夏 时间:2024年1月20日猴子吃桃问题-1 猴子第一天摘了许多桃子,第一天吃了一半,;第二天又吃了一半, 后面每天都是这样吃…

【Java】HttpServlet类简单方法和请求显示

1、HttpServlet类简介🍀 Servlet类中常见的三个类有:☑️HttpServlet类,☑️HttpServletRequest类,☑️HttpResponse类 🐬其中,HttpServlet首先必须读取Http请求的内容。Servlet容器负责创建HttpServlet对…

Deepin_Ubuntu_查看树形目录结构(tree)

Linux系统(Deepin、Ubuntu)中,可以使用tree命令来查看树形目录结构,下面是一些示例: 查看当前目录的树形结构: tree查看指定目录的树形结构,例如/etc/X11/fonts目录: tree /etc/X…

CentOS 7安装Java并配置环境

一、安装Java环境 1、检查系统是否安装Java [rootlocalhost ~]# java -version 2、更新系统软件包 [rootlocalhost ~]# yum update #遇到[y/n],选择y并回车,耐心等待下载完毕,之后系统会自动检验更新的软件包遇到 /var/run/yum.pid 已被锁定 /var/…

【Go面试向】实现map稳定的有序遍历的方式

问题 大家好 我是寸铁👊 总结了一篇实现map稳定的有序遍历的方式探讨的文章✨ 喜欢的小伙伴可以点点关注 💝 你对 map 了解多少?如果要实现第一个稳定的有序遍历有哪些方式? 回答 你对 map 了解多少? 我对map有一定的…

Centos7 如何设置开机启动某个程序

以设置自动启动sentinel-dashboard作为案例 要在CentOS 7上设置开机启动一个Java程序,你可以按照以下步骤进行操作: 1. 进入应用程序的目录 cd /usr/localvim sentinel-dashboard.sh 2. 在sentinel-dashboard.sh 文件中 输入启动脚本 nohup java -D…

『C++成长记』模板

🔥博客主页:小王又困了 📚系列专栏:C 🌟人之为学,不日近则日退 ❤️感谢大家点赞👍收藏⭐评论✍️ 目录 一、泛型编程 二、函数模板 📒2.1函数模板概念 📒2.2函数…

[设计模式Java实现附plantuml源码~创建型] 多态工厂的实现——工厂方法模式

前言: 为什么之前写过Golang 版的设计模式,还在重新写Java 版? 答:因为对于我而言,当然也希望对正在学习的大伙有帮助。Java作为一门纯面向对象的语言,更适合用于学习设计模式。 为什么类图要附上uml 因为很…