熊貓數據集_熊貓邁向數據科學的第二部分

熊貓數據集

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.pswp.cn/news/390018.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390018.shtml
英文地址,請注明出處:http://en.pswp.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;把新的數據插入到已經排好的數據列中。將第一個數和第…