熊猫数据集_熊猫迈向数据科学的第二部分

熊猫数据集

If you haven’t read the first article then it is advised that you go through that before continuing with this article. You can find that article here. So far we have learned how to access data in different ways. Now we will learn how to analyze data to get better understanding and then to manipulate it.

如果您还没有阅读第一篇文章,那么建议您在继续阅读本文之前先进行阅读。 您可以在这里找到该文章。 到目前为止,我们已经学习了如何以不同的方式访问数据。 现在,我们将学习如何分析数据以获得更好的理解,然后进行操作。

So just to give overview, in this article we are going to learn

因此,为了概述,在本文​​中我们将学习

  1. How to summarize data?

    如何汇总数据?
  2. How to manipulate data?

    如何处理数据?

汇总数据 (Summarizing Data)

We have been using different methods to view data which is helpful if we wanted to summarize data for specific rows or columns. However, pandas provide simpler methods to view data.

我们一直在使用不同的方法来查看数据,这对于希望汇总特定行或列的数据很有帮助。 但是,熊猫提供了更简单的方法来查看数据。

If we want to see few data items to understand what kind of data is present in dataset pandas provide methods like head() and tail(). head() provides few rows from the top, by default it provide first five rows and tail(), as you might have guessed, provide rows from bottom of dataset. You can also specify a number to show how many rows you want to display as head(n) or tail(n).

如果我们希望看到很少的数据项以了解数据集中存在的数据类型,熊猫可以提供head()tail()之类的方法head()从顶部提供几行,默认情况下,它提供前五行而您可能已经猜到了tail(),从数据集的底部提供行。 您还可以指定一个数字,以显示要显示为head(n)或tail(n)的行数。

>> print(titanic_data.head())output : PassengerId  Survived  Pclass  .......
0 1 0 3
1 2 1 1
2 3 1 3
3 4 1 1
4 5 0 3
[5 rows x 12 columns]
>> print(titanic_data.tail())output : PassengerId Survived Pcl Name .........
886 887 0 2 Montvila, Rev. Juozas
887 888 1 1 Graham, Miss. Margaret Edith
888 889 0 3 Johnston, Miss. Catherine Hele..
889 890 1 1 Behr, Mr. Karl Howell
890 891 0 3 Dooley, Mr. Patrick[5 rows x 12 columns]>> print(titanic_data.tail(3))output : PassengerId Survived Pcl Name .........
888 889 0 3 Johnston, Miss. Catherine Hele..
889 890 1 1 Behr, Mr. Karl Howell
890 891 0 3 Dooley, Mr. Patrick[3 rows x 12 columns]

We can also display the data statistics of our dataset. We use describe() method to get statistics for every column. We can also get statistic for a specific column.

我们还可以显示数据集的数据统计信息。 我们使用describe()方法获取每一列的统计信息。 我们还可以获取特定列的统计信息。

>> print(titanic_data.describe())output :       PassengerId    Survived      Pclass         Age    SibSp  ...
count 891.000000 891.000000 891.000000 714.000000 891.000000
mean 446.000000 0.383838 2.308642 29.699118 0.523008
std 257.353842 0.486592 0.836071 14.526497 1.102743
min 1.000000 0.000000 1.000000 0.420000 0.000000
25% 223.500000 0.000000 2.000000 20.125000 0.000000
50% 446.000000 0.000000 3.000000 28.000000 0.000000
75% 668.500000 1.000000 3.000000 38.000000 1.000000
max 891.000000 1.000000 3.000000 80.000000 8.000000>> print(titanic_data.Fare.decribe())output :count 891.000000
mean 32.204208
std 49.693429
min 0.000000
25% 7.910400
50% 14.454200
75% 31.000000
max 512.329200
Name: Fare, dtype: float64

Remember, it only return statistical data for numerical columns. It displays statistics like count i.e number of data points in that column, mean of data points, standard deviation and so on. If you do not want to see this whole stats then you can also call on these parameters individually.

请记住,它仅返回数字列的统计数据。 它显示统计信息,例如计数,即该列中数据点的数量,数据点的平均值,标准偏差等。 如果您不希望看到整个统计信息,则也可以单独调用这些参数。

>> print(titanic_data.Fare.mean())output :32.204208

处理数据 (Manipulating Data)

  1. map(): It is use to manipulate data in a Series. We use map() method on a columns of dataset. map() takes a function as parameter and that function takes a data point from specified column as parameter. map() iterates over all data points of a column and then returns new updated series.

    map() :用于处理系列中的数据。 我们在dataset. map()的列上使用map()方法dataset. map() dataset. map()将函数作为参数,而该函数将指定列中的数据点作为parameter. map() parameter. map()遍历列的所有数据点,然后返回新的更新的系列。

  2. apply(): It is used to manipulate data in a Dataframe. It behaves almost same as map() but it takes Series (row or column) as parameter to given function which in return provide updated Series and finally after all iteration of Series, apply() returns a new Dataframe.

    apply() :用于处理数据帧中的数据。 它的行为几乎与map()相同,但是它将Series(行或列)作为给定函数的参数,该函数提供更新的Series,最后在Series的所有迭代之后, apply()返回一个新的Dataframe。

# Here we define a function which will be used as parameter to map()>> def updateUsingMap(data_point):
'''
This function make data more readable by changing
Survived columns values to Yes if 1
and No if 0
Parameters
----------
data_point : int Returns
-------
data_point : string '''
updated_data = ''
if(data_point==0):
updated_data = "No"
else:
updated_data = "Yes"
return updated_data>> print(titatic_data.Survived.map(updateUsingMap))output :0 No
1 Yes
2 Yes
3 Yes
4 No
.....
Name: Survived, Length: 891, dtype: object# Here we define a function which will be used as parameter to apply()def updateUsingApply(row):
'''
This function make data more readable by changing
Survived columns values to Yes if 1
and No if 0
Parameters
----------
row : Series Returns
-------
row : Series '''if(row.Survived==0):
row.Survived = "No"
else:
row.Survived = "Yes"
return row
>> print(titatic_data.apply(updateUsingMap,axis = 'columns'))output : PassengerId Survived Pclass .......
0 1 No 3
1 2 Yes 1
2 3 Yes 3
3 4 Yes 1
4 5 No 3
.. ... ... ...
[891 rows x 12 columns]

One thing needs to be clear here that these methods do not manipulate or change original data. It creates a new Series or Dataframe. As you noticed that we used another parameter in apply() method that is axis. It is used to specify that we want to change data along the rows. In order to change data along the columns we would have supplied value of axis as index.

需要明确的一点是,这些方法不会操纵或更改原始数据。 它创建一个新的系列或数据框。 您已经注意到,我们在apply()方法中使用了另一个参数axis。 它用于指定我们要沿行更改数据。 为了沿列更改数据,我们将提供轴的值作为索引。

I think it is enough for this article. Let this information sink in and then we can start with next article to explore few more methods in Pandas till then keep practicing. Happy Coding! 😄

我认为这篇文章就足够了。 让这些信息沉入其中,然后我们可以从下一篇文章开始,探索熊猫中的其他方法,然后继续练习。 编码愉快! 😄

普通英语的Python (Python In Plain English)

Did you know that we have three publications and a YouTube channel? Find links to everything at plainenglish.io!

您知道我们有三个出版物和一个YouTube频道吗? 在plainenglish.io上找到所有内容的链接!

翻译自: https://medium.com/python-in-plain-english/pandas-first-step-towards-data-science-part-2-fd35266deab4

熊猫数据集

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

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

相关文章

Python基础综合练习

Pycharm开发环境设置与熟悉。 练习基本输入输出&#xff1a; print(你好,{}..format(name)) print(sys.argv) 库的使用方法&#xff1a; import ... from ... import ... 条件语句&#xff1a; if (abs(pos()))<1: break 循环语句&#xff1a; for i in range(5): while Tru…

POJ 3608 旋转卡壳

思路&#xff1a; 旋转卡壳应用 注意点&边 边&边 点&点 三种情况 //By SiriusRen #include <cmath> #include <cstdio> #include <algorithm> using namespace std; const double eps1e-5; const int N10050; typedef double db; int n,m; str…

405. 数字转换为十六进制数

405. 数字转换为十六进制数 给定一个整数&#xff0c;编写一个算法将这个数转换为十六进制数。对于负整数&#xff0c;我们通常使用 补码运算 方法。 注意: 十六进制中所有字母(a-f)都必须是小写。 十六进制字符串中不能包含多余的前导零。如果要转化的数为0&#xff0c;那么…

为什么我要重新开始数据科学

I’m feeling stuck.我感觉卡住了。 In my current work and in the content I create (videos and blog posts), I feel like I’ve begun to stall out. Most of the consumers of my content are at the start of their data science journey. The longer I’m in the fiel…

蓝牙协议 HFP,HSP,A2DP,A2DP_CT,A2DP_TG,AVRCP,OPP,PBAP,SPP,FTP,TP,DTMF,DUN,SDP

简介&#xff1a; HSP&#xff08;手机规格&#xff09;– 提供手机&#xff08;移动电话&#xff09;与耳机之间通信所需的基本功能。 HFP&#xff08;免提规格&#xff09;– 在 HSP 的基础上增加了某些扩展功能&#xff0c;原来只用于从固定车载免提装置来控制移动电话。 A2…

482. 密钥格式化

482. 密钥格式化 有一个密钥字符串 S &#xff0c;只包含字母&#xff0c;数字以及 ‘-’&#xff08;破折号&#xff09;。其中&#xff0c; N 个 ‘-’ 将字符串分成了 N1 组。 给你一个数字 K&#xff0c;请你重新格式化字符串&#xff0c;使每个分组恰好包含 K 个字符。特…

安装mariadb、安装Apache

2019独角兽企业重金招聘Python工程师标准>>> 安装mariadb 安装mariadb的步骤与安装mysql的一样 下载二进制源码包 再用tar 解压&#xff0c;创建/data/mariadb目录和用户 初始化 编译启动脚本 启动 安装Apache Apache是软件基金会的名字&#xff0c;软件的名字叫htt…

数据科学的发展_数据科学的发展与发展

数据科学的发展There’s perhaps nothing that sets the 21st century apart from others more than the concept of data. Every interaction we have with a connected device creates a data record, and beams it back to some data store for tracking and analysis. Inte…

Polling 、Long Polling 和 WebSocket

最近在学习研究WebSocket,了解到Polling 和Long Polling,翻阅了一些博文&#xff0c;根据自己的理解&#xff0c;做个学习笔记 Polling &#xff08;轮询&#xff09;&#xff1a; 这种方式就是客户端定时向服务器发送http的Get请求&#xff0c;服务器收到请求后&#xff0c;就…

惯性张量的推理_选择合适的intel工作站处理器进行张量流推理和开发

惯性张量的推理With the increasing number of data scientists using TensorFlow, it might be a good time to discuss which workstation processor to choose from Intel’s lineup. You have several options to choose from:随着使用TensorFlow的数据科学家数量的增加&am…

MongoDB数据库查询性能提高40倍

MongoDB数据库查询性能提高40倍 大家在使用 MongoDB 的时候有没有碰到过性能问题呢&#xff1f;下面这篇文章主要给大家分享了MongoDB数据库查询性能提高40倍的经历&#xff0c;需要的朋友可以参考借鉴&#xff0c;下面来一起看看吧。 前言 数据库性能对软件整体性能有着至关重…

通过Ajax方式上传文件(input file),使用FormData进行Ajax请求

<script type"text/jscript">$(function () {$("#btn_uploadimg").click(function () {var fileObj document.getElementById("FileUpload").files[0]; // js 获取文件对象if (typeof (fileObj) "undefined" || fileObj.size …

并发插入数据库会导致失败吗_会导致业务失败的数据分析方法

并发插入数据库会导致失败吗The true value of data depends on business insight.Data analysis is one of the most powerful resources an enterprise has. However, if the tools and processes used are not friendly and widely available to the business users who nee…

434. 字符串中的单词数

434. 字符串中的单词数 统计字符串中的单词个数&#xff0c;这里的单词指的是连续的不是空格的字符。 请注意&#xff0c;你可以假定字符串里不包括任何不可打印的字符。 示例: 输入: “Hello, my name is John” 输出: 5 解释: 这里的单词是指连续的不是空格的字符&#x…

zooland 新开源的RPC项目,希望大家在开发的微服务的时候多一种选择,让微服务开发简单,并且容易上手。...

zooland 我叫它动物园地&#xff0c;一个构思很长时间的一个项目。起初只是觉得各种通信框架都封装的很好了&#xff0c;但是就是差些兼容&#xff0c;防错&#xff0c;高可用。同时在使用上&#xff0c;不希望有多余的代码&#xff0c;像普通接口一样使用就可以了。 基于这些想…

187. 重复的DNA序列

187. 重复的DNA序列 所有 DNA 都由一系列缩写为 ‘A’&#xff0c;‘C’&#xff0c;‘G’ 和 ‘T’ 的核苷酸组成&#xff0c;例如&#xff1a;“ACGAATTCCG”。在研究 DNA 时&#xff0c;识别 DNA 中的重复序列有时会对研究非常有帮助。 编写一个函数来找出所有目标子串&am…

牛客网_Go语言相关练习_选择题(2)

注&#xff1a;题目来源均出自牛客网。 一、选择题 Map&#xff08;集合&#xff09;属于Go的内置类型&#xff0c;不需要引入其它库即可使用。 Go-Map_菜鸟教程 在函数声明中&#xff0c;返回的参数要么都有变量名&#xff0c;要么都没有。 C选项函数声明语法有错误&#xff0…

机器学习模型部署_9月版部署机器学习模型

机器学习模型部署每月版 (MONTHLY EDITION) Often, the last step of a Data Science task is deployment. Let’s say you’re working at a big corporation. You’re building a project for a customer of the corporation and you’ve created a model that performs well…

352. 将数据流变为多个不相交区间

352. 将数据流变为多个不相交区间 给你一个由非负整数 a1, a2, …, an 组成的数据流输入&#xff0c;请你将到目前为止看到的数字总结为不相交的区间列表。 实现 SummaryRanges 类&#xff1a; SummaryRanges() 使用一个空数据流初始化对象。void addNum(int val) 向数据流中…

Java常用的八种排序算法与代码实现

排序问题一直是程序员工作与面试的重点&#xff0c;今天特意整理研究下与大家共勉&#xff01;这里列出8种常见的经典排序&#xff0c;基本涵盖了所有的排序算法。 1.直接插入排序 我们经常会到这样一类排序问题&#xff1a;把新的数据插入到已经排好的数据列中。将第一个数和第…