熊猫数据集_熊猫迈向数据科学的第二部分
熊猫数据集
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
因此,为了概述,在本文中我们将学习
- How to summarize data?如何汇总数据?
- 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.000000mean 32.204208std 49.693429min 0.00000025% 7.91040050% 14.45420075% 31.000000max 512.329200Name: 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)
map()
: It is use to manipulate data in a Series. We usemap()
method on a columns ofdataset. map()
takes a function as parameter and that function takes a data point from specified column asparameter. 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()
遍历列的所有数据点,然后返回新的更新的系列。apply()
: It is used to manipulate data in a Dataframe. It behaves almost same asmap()
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 No1 Yes2 Yes3 Yes4 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!
熊猫数据集_熊猫迈向数据科学的第二部分相关推荐
- 熊猫数据集_熊猫迈向数据科学的第一步
熊猫数据集 I started learning Data Science like everyone else by creating my first model using some machi ...
- 熊猫数据集_熊猫迈向数据科学的第三部分
熊猫数据集 Data is almost never perfect. Data Scientist spend more time in preprocessing dataset than in ...
- 熊猫数据集_使用大数据的熊猫
熊猫数据集 减少多达90%的内存使用量的提示 (Tips for reducing memory usage by up to 90%) When working using pandas with ...
- 葡萄酒数据集_如何使用数据科学来理解什么使葡萄酒味道更好
葡萄酒数据集 Data Science. It's been touted as the sexiest job of the 21st century. Everyone - from compan ...
- 微观计量经济学_微观经济学与数据科学
微观计量经济学 什么是经济学和微观经济学? (What are Economics and Microeconomics?) Economics is a social science concern ...
- 熊猫数据集_为数据科学拆箱熊猫
熊猫数据集 If you are already familiar with NumPy, Pandas is just a package build on top of it. Pandas pr ...
- 熊猫数据集_对熊猫数据框使用逻辑比较
熊猫数据集 P (tPYTHON) Logical comparisons are used everywhere. 逻辑比较随处可见 . The Pandas library gives you a ...
- 熊猫数据集_大熊猫数据框的5个基本操作
熊猫数据集 Tips and Tricks for Data Science 数据科学技巧与窍门 Pandas is a powerful and easy-to-use software libra ...
- 熊猫分发_熊猫新手:第一部分
熊猫分发 For those just starting out in data science, the Python programming language is a pre-requisite ...
最新文章
- CSS 之 控制图片与文字对齐
- java_IO总结(1)
- Always keep in mind
- oracle开窗函数是什么,ORACLE数据库(六)-----开窗函数
- u 去除index.php,ThinkPHP去除url中的index.php
- PostgreSQL中定时job执行(pgAgent)
- android冻结命令,在Android上使用冻结tensorflow图中的变量
- Ubuntu使用tcpdump工具
- boost.asio mysql_boost asio学习笔记
- OpenGL学习(二)用户与交互
- SAS进行多元回归线性分析
- JAVA开源B2C系统
- mysql先进后出_栈、队列中“先进先出”,“后进先出”的含义
- 大一计算机考试题库打字题,大一计算机考试题库
- Vue项目-前端实现导出功能
- 小米校招 C++研发 相机部 一二面
- sharding-jdbc系列之按月动态分表(十二)
- C语言试题123之有 5 个人坐在一起,问第五个人多少岁?他说比第 4 个人大 2 岁。问第 4 个人岁数,他说比第 3 个人大 2 岁。问第三个人,又说比第 2 人大两岁。问第 2 个人,说比第一个
- discuz admin.php换名,discuz更换域名修改方法
- 实现简易版德州扑克|学习麻瓜编程以项目为导向入门前端 HTML+CSS+JS