數據科學 python_如何使用Python為數據科學建立肌肉記憶

數據科學 python

by Zhen Liu

劉震

首先:數據預處理 (Up first: data preprocessing)

Do you feel frustrated by breaking your data analytics flow when searching for syntax? Why do you still not remember it after looking up it for the third time?? It’s because you haven’t practiced it enough to build muscle memory for it yet.

搜索語法時,您是否因中斷數據分析流程而感到沮喪? 為什么第三遍查詢后仍不記得呢? 這是因為您尚未練習足夠的肌肉記憶。

Now, imagine that when you are coding, the Python syntax and functions just fly out from your fingertips following your analytical thoughts. How great is that! This tutorial is to help you get there.

現在,想象一下,當您進行編碼時,Python語法和函數會按照您的分析思路從您的指尖飛出。 那太好了! 本教程是為了幫助您到達那里。

I recommend practicing this script every morning for 10 mins, and repeating it for a week. It’s like doing a few small crunches a day — not for your abs, but for your data science muscles. Gradually, you’ll notice the improvement in data analytics programming efficiency after this repeat training.

我建議每天早上練習此腳本10分鐘,然后重復一周。 這就像一天做幾次小動作-不是為了您的腹肌,而是為了您的數據科學力量。 經過反復的培訓,您會逐漸發現數據分析編程效率的提高。

To begin with my ‘data science workout’, in this tutorial we’ll practice the most common syntax for data preprocessing as a warm-up session ;)

首先,從我的“數據科學鍛煉”開始,在本教程中,我們將作為預熱課程練習數據預處理的最常用語法;)

Contents:
0 . Read, View and Save data1 . Table’s Dimension and Data Types2 . Basic Column Manipulation3 . Null Values: View, Delete and Impute4 . Data Deduplication

0.讀取,查看和保存數據 (0. Read, View and Save data)

First, load the libraries for our exercise:

首先,為我們的練習加載庫:

Now we’ll read data from my GitHub repository. I downloaded the data from Zillow.

現在,我們將從GitHub存儲庫中讀取數據。 我從Zillow下載了數據。

And the results look like this:

結果看起來像這樣:

Saving a file is dataframe.to_csv(). If you don’t want the index number to be saved, use dataframe.to_csv( index = False ).

保存文件為dataframe.to_csv()。 如果您不希望保存索引號,請使用dataframe.to_csv(index = False)。

1。 表的維度和數據類型 (1 . Table’s Dimension and Data Types)

1.1尺寸 (1.1 Dimension)

How many rows and columns in this data?

此數據中有多少行和幾列?

1.2數據類型 (1.2 Data Types)

What are the data types of your data, and how many columns are numeric?

數據的數據類型是什么,數字有多少列?

Output of the first few columns’ data types:

前幾列的數據類型的輸出:

If you want to be more specific about your data, use select_dtypes() to include or exclude a data type. Question: if I only want to look at 2018’s data, how do I get that?

如果要更具體地說明數據,請使用select_dtypes()包括或排除數據類型。 問題:如果我只想看一下2018年的數據,那我怎么得到呢?

2.基本列操作 (2. Basic Column Manipulation)

2.1按列子集數據 (2.1 Subset data by columns)

Select columns by data types:

按數據類型選擇列:

For example, if you only want float and integer columns:

例如,如果只需要浮點數和整數列:

Select and drop columns by names:

按名稱選擇和刪除列:

2.2重命名列 (2.2 Rename Columns)

How do I rename the columns if I don’t like them? For example, change ‘State’ to ‘state_’; ‘City’ to ‘city_’:

如果我不喜歡這些列,該如何重命名它們? 例如,將“狀態”更改為“ state_”; 從“城市”到“ city_”:

3.空值:查看,刪除和插入 (3. Null Values: View, Delete and Impute)

3.1多少行和列具有空值? (3.1 How many rows and columns have null values?)

The outputs of isnull.any() versus isnull.sum():

isnull.any()與isnull.sum()的輸出:

Select data that isn’t null in one column, for example, ‘Metro’ isn’t null.

選擇在一列中不為空的數據,例如,“ Metro”不為空。

3.2為一組固定的列選擇不為空的行 (3.2 Select rows that are not null for a fixed set of columns)

Select a subset of data that doesn’t have null after 2000:

選擇2000年后不為空的數據子集:

If you want to select the data in July, you need to find the columns containing ‘-07’. To see if a string contains a substring, you can use substring in string, and it’ll output true or false.

如果要選擇7月的數據,則需要查找包含“ -07”的列。 要查看字符串是否包含子字符串,可以在字符串中使用子字符串,它會輸出true或false。

3.3空值子集行 (3.3 Subset Rows by Null Values)

Select rows where we want to have at least 50 non-NA values, but don’t need to be specific about the columns:

選擇我們希望至少具有50個非NA值但不需要具體說明列的行:

3.4丟失和歸類缺失值 (3.4 Drop and Impute Missing Values)

Fill NA or impute NA:

填寫NA或估算NA:

Use your own condition to fill using the where function:

使用您自己的條件使用where函數填充:

4.重復數據刪除 (4. Data Deduplication)

We need to make sure there’s no duplicated rows before we aggregate data or join them.

在聚合數據或將它們聯接之前,我們需要確保沒有重復的行。

We want to see whether there are any duplicated cities/regions. We need to decide what unique ID (city, region) we want to use in the analysis.

我們想看看是否有重復的城市/地區。 我們需要確定要在分析中使用的唯一ID(城市,地區)。

刪除重復的值。 (Drop Duplicated values.)

The ‘CountyName’ and ‘SizeRank’ combination is unique already. So we just use the columns to demonstrate the syntax of drop_duplicated.

“ CountyName”和“ SizeRank”組合已經是唯一的。 因此,我們僅使用列來演示drop_duplicated的語法。

That’s it for the first part of my series on building muscle memory for data science in Python. The full script can be found here.

這就是我在Python中為數據科學構建肌肉內存的系列文章的第一部分。 完整的腳本可以在這里找到。

Stay tuned! My next tutorial will show you how to ‘curl the data science muscles’ for slicing and dicing data.

敬請關注! 我的下一個教程將向您展示如何“卷曲數據科學的力量”來對數據進行切片和切塊。

Follow me and give me a few claps if you find this helpful :)

跟隨我,如果您覺得有幫助,請給我一些鼓掌:)

While you are working on Python, maybe you’ll be interested in my previous article:

在使用Python時,也許您會對我以前的文章感興趣:

Learn Spark for Big Data Analytics in 15 mins!I guarantee you that this short tutorial will save you a TON of time from reading the long documentations. Ready to…towardsdatascience.com

15分鐘之內即可學習Spark for Big Data Analytics! 我向您保證,這個簡短的教程將為您節省閱讀冗長文檔的時間。 準備去…朝向datascience.com

翻譯自: https://www.freecodecamp.org/news/how-to-build-up-your-muscle-memory-for-data-science-with-python-5960df1c930e/

數據科學 python

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/393113.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/393113.shtml
英文地址,請注明出處:http://en.pswp.cn/news/393113.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

oracle 管道通信,oracle管道化表函數

轉自:http://pengfeng.javaeye.com/blog/260360在我所做過和參與的大多數項目中,都會有用戶提出的復雜的一些統計報表之內的功能要求,根據統計的復雜程度、效率及JAVA程序調用的方便性方面考慮,主要總結出以下幾種方案: 1、SQL語句 該方案只能實現一些相…

ebtables之BROUTING和PREROUTING的redirect的區別

ebtables和iptables實用工具都使用了Netfilter框架,這是它們一致的一方面,然而對于這兩者還真有一些需要聯動的地方。很多人不明白ebtales的broute表的redirect和nat表PREROUTING的redirect的區別,其實只要記住兩點即可,那就是對于…

LVS的四種模式的實現

LVS 是四層負載均衡,也就是說建立在 OSI 模型的第四層——傳輸層之上,傳輸層上有我們熟悉的 TCP/UDP,LVS 支持 TCP/UDP 的負載均衡。LVS 的轉發主要通過修改 IP 地址(NAT 模式,分為源地址修改 SNAT 和目標地址修改 DNA…

MyISAM與InnoDB兩者之間區別與選擇,詳細總結,性能對比

1、MyISAM:默認表類型,它是基于傳統的ISAM類型,ISAM是Indexed Sequential Access Method (有索引的順序訪問方法) 的縮寫,它是存儲記錄和文件的標準方法。不是事務安全的,而且不支持外鍵,如果執行大量的sel…

leetcode557. 反轉字符串中的單詞 III

給定一個字符串,你需要反轉字符串中每個單詞的字符順序,同時仍保留空格和單詞的初始順序。 示例: 輸入:“Let’s take LeetCode contest” 輸出:“s’teL ekat edoCteeL tsetnoc” 代碼 class Solution {public St…

linux命令數據盤分多個區,pvmove命令 – 移動物理盤區

pvmove命令的作用是可以將源物理卷上的物理盤區移動到一個或多個其他的目標物理卷。使用pvmove命令時可以指定一個源日志或卷。在這種情況下,只有邏輯卷使用的區才會被移動到目標物理卷上的空閑或指定的區。如果沒有指定的物理卷,則使用卷組的默認規則分…

spanning-tree extend system-id

spanning-tree extend system-id 在交換機上啟用extended-system ID 特征使其支持 1024 MAC 地址, 在全局模式下使用 spanning-tree extend system-id命令.禁用時前面加 no。 spanning-tree extend system-id no spanning-tree extend system-id 命令用法 在不提供 1024 MAC 地…

leetcode841. 鑰匙和房間(bfs)

有 N 個房間,開始時你位于 0 號房間。每個房間有不同的號碼:0,1,2,…,N-1,并且房間里可能有一些鑰匙能使你進入下一個房間。 在形式上,對于每個房間 i 都有一個鑰匙列表 rooms[i]&a…

Codeforces 235C Cyclical Quest (后綴自動機)

題目鏈接: https://codeforces.com/contest/235/problem/C 題解: 對大串建后綴自動機 對詢問串復制拆環。這里一定要注意是復制一個循環節不是復制整個串!循環節是要整除的那種 然后要做的實際上是在大串上跑,每經過一個點求出當前的最長公共子串&#x…

泛型型協變逆變_Java泛型類型簡介:協變和逆變

泛型型協變逆變by Fabian Terh由Fabian Terh Java泛型類型簡介:協變和逆變 (An introduction to generic types in Java: covariance and contravariance) 種類 (Types) Java is a statically typed language, which means you must first declare a variable and …

安卓系統換成linux系統軟件,將舊安卓手機打造成“簡易linux”機器,并部署AdGuardHome...

從原教程的安裝Linux Deploy 完成后,在配置 Linux下載鏡像的一些東西時有些許出入。首先,我是用的下載源地址是 http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports 清華的源挺好用的。 其他有出入的配置如圖(記得把源地址改清華的,華中科大…

let與expr命令的用法與實戰案例

let命令的用法 格式: let 賦值表達式 【注】let賦值表達式功能等同于:(賦值表達式) 例子:給自變量i加8 12345678[rootXCN ~]# i2 [rootXCN ~]# let ii8 [rootXCN ~]# echo $i 10[rootXCN ~]# ii8 #去掉let定義 [root…

在使用ToolBar + AppBarLayout,實現上劃隱藏Toolbar功能,遇到了一個坑。

問題:Android5.0以下版本Toolbar不顯示沉浸式狀態欄,沒有這個問題,但是5.0以上版本,就出現了莫名其妙的陰影問題,很是頭疼。 分享一下我的解決方案: 在AppBarLayout中加一個屬性: app:elevation…

leetcode1476. 子矩形查詢

請你實現一個類 SubrectangleQueries ,它的構造函數的參數是一個 rows x cols 的矩形(這里用整數矩陣表示),并支持以下兩種操作: updateSubrectangle(int row1, int col1, int row2, int col2, int newValue) 用 new…

msbuild構建步驟_如何按照以下步驟構建最終的AI聊天機器人

msbuild構建步驟by Paul Pinard保羅皮納德(Paul Pinard) 如何按照以下步驟構建最終的AI聊天機器人 (How to build the ultimate AI chatbot by following these steps) 快速指南,可幫助您避免常見的陷阱 (A quick guide that helps you avoid common pitfalls) Bui…

第一章:最小可行區塊鏈

概覽區塊數據結構區塊哈希創世塊創建區塊保存區塊鏈驗證區塊完整性選擇最長鏈節點間通信操作節點架構運行測試小結概覽 區塊鏈的基礎概念非常簡單, 說白了就是一個維護著一個持續增長的有序數據記錄列表的這么一個分布式數據庫。在此章節中我們將實現一個簡單的玩具版的區塊鏈。…

Oracle Controlfile控制文件中記錄的信息片段sections

初學Oracle的朋友肯定對Controlfile控制文件中到底記錄了何種的信息記錄而感到好奇,實際上我們可以通過一個視圖v$controlfile_record_section來了解控制文件的信息片段: SQL> select type, record_size, records_total from v$controlfile_record_s…

linux 怎么禁止遍歷目錄,linux下遍歷目錄功能實現

/*編譯:dir:dir.cgcc -o $ $<*/#include #include #include #include #include int do_search_dir(char *path);int do_check_dir(char *fullpath, char* truefullpath);void usage(char *apps);int count 0;intmain(int argc,char **argv){char fullpath[…

leetcode面試題 16.26. 計算器(棧)

給定一個包含正整數、加()、減(-)、乘(*)、除(/)的算數表達式(括號除外)&#xff0c;計算其結果。 表達式僅包含非負整數&#xff0c;&#xff0c; - &#xff0c;*&#xff0c;/ 四種運算符和空格 。 整數除法僅保留整數部分。 示例 1: 輸入: “32*2” 輸出: 7 代碼 clas…

團隊項目電梯會議視頻

http://v.youku.com/v_show/id_XMjcyMjI3Mjk2NA.html?spma2hzp.8244740.userfeed.5!2~5~5~5!3~5~A轉載于:https://www.cnblogs.com/jingxiaopu/p/6749776.html