魅族mx5游戲模式小熊貓_您不知道的5大熊貓技巧

魅族mx5游戲模式小熊貓

重點 (Top highlight)

I’ve been using pandas for years and each time I feel I am typing too much, I google it and I usually find a new pandas trick! I learned about these functions recently and I deem them essential because of ease of use.

我已經使用熊貓多年了,每次我輸入太多單詞時,我都會用google搜索它,而且我通常會發現一個新的熊貓技巧! 我最近了解了這些功能,并且由于易于使用,我認為它們是必不可少的。

1.功能之間 (1. between function)

Image for post
GiphyGiphy的 Gif

I’ve been using “between” function in SQL for years, but I only discovered it recently in pandas.

多年來,我一直在SQL中使用“ between”功能,但最近才在pandas中發現它。

Let’s say we have a DataFrame with prices and we would like to filter prices between 2 and 4.

假設我們有一個帶有價格的DataFrame,并且我們希望在2到4之間過濾價格。

df = pd.DataFrame({'price': [1.99, 3, 5, 0.5, 3.5, 5.5, 3.9]})

With between function, you can reduce this filter:

使用between功能,可以減少此過濾器:

df[(df.price >= 2) & (df.price <= 4)]

To this:

對此:

df[df.price.between(2, 4)]
Image for post

It might not seem much, but those parentheses are annoying when writing many filters. The filter with between function is also more readable.

看起來似乎不多,但是編寫許多過濾器時這些括號令人討厭。 具有中間功能的過濾器也更易讀。

between function sets interval left <= series <= right.

功能集之間的間隔左<=系列<=右。

2.使用重新索引功能固定行的順序 (2. Fix the order of the rows with reindex function)

Image for post
giphygiphy

Reindex function conforms a Series or a DataFrame to a new index. I resort to the reindex function when making reports with columns that have a predefined order.

Reindex函數使Series或DataFrame符合新索引。 當使用具有預定義順序的列制作報表時,我求助于reindex函數。

Let’s add sizes of T-shirts to our Dataframe. The goal of analysis is to calculate the mean price for each size:

讓我們在數據框中添加T恤的尺寸。 分析的目的是計算每種尺寸的平ASP格:

df = pd.DataFrame({'price': [1.99, 3, 5], 'size': ['medium', 'large', 'small']})df_avg = df.groupby('size').price.mean()
df_avg
Image for post

Sizes have a random order in the table above. It should be ordered: small, medium, large. As sizes are strings we cannot use the sort_values function. Here comes reindex function to the rescue:

尺寸在上表中具有隨機順序。 應該訂購:小,中,大。 由于大小是字符串,因此我們不能使用sort_values函數。 這里有reindex函數來解救:

df_avg.reindex(['small', 'medium', 'large'])
Image for post

By

通過

3.描述類固醇 (3. Describe on steroids)

Image for post
GiphyGiphy的 Gif

Describe function is an essential tool when working on Exploratory Data Analysis. It shows basic summary statistics for all columns in a DataFrame.

當進行探索性數據分析時,描述功能是必不可少的工具。 它顯示了DataFrame中所有列的基本摘要統計信息。

df.price.describe()
Image for post

What if we would like to calculate 10 quantiles instead of 3?

如果我們想計算10個分位數而不是3個分位數怎么辦?

df.price.describe(percentiles=np.arange(0, 1, 0.1))
Image for post

Describe function takes percentiles argument. We can specify the number of percentiles with NumPy's arange function to avoid typing each percentile by hand.

描述函數采用百分位數參數。 我們可以使用NumPy的arange函數指定百分位數,以避免手動鍵入每個百分位數。

This feature becomes really useful when combined with the group by function:

與group by函數結合使用時,此功能將非常有用:

df.groupby('size').describe(percentiles=np.arange(0, 1, 0.1))
Image for post

4.使用正則表達式進行文本搜索 (4. Text search with regex)

Image for post
GiphyGiphy的 Gif

Our T-shirt dataset has 3 sizes. Let’s say we would like to filter small and medium sizes. A cumbersome way of filtering is:

我們的T恤數據集有3種尺寸。 假設我們要過濾中小型尺寸。 繁瑣的過濾方式是:

df[(df['size'] == 'small') | (df['size'] == 'medium')]

This is bad because we usually combine it with other filters, which makes the expression unreadable. Is there a better way?

這很不好,因為我們通常將其與其他過濾器結合使用,從而使表達式不可讀。 有沒有更好的辦法?

pandas string columns have an “str” accessor, which implements many functions that simplify manipulating string. One of them is “contains” function, which supports search with regular expressions.

pandas字符串列具有“ str”訪問器,該訪問器實現了許多簡化操作字符串的功能。 其中之一是“包含”功能,該功能支持使用正則表達式進行搜索。

df[df['size'].str.contains('small|medium')]

The filter with “contains” function is more readable, easier to extend and combine with other filters.

具有“包含”功能的過濾器更具可讀性,更易于擴展并與其他過濾器組合。

5.比帶有熊貓的內存數據集更大 (5. Bigger than memory datasets with pandas)

Image for post
giphygiphy

pandas cannot even read bigger than the main memory datasets. It throws a MemoryError or Jupyter Kernel crashes. But to process a big dataset you don’t need Dask or Vaex. You just need some ingenuity. Sounds too good to be true?

熊貓讀取的數據甚至不能超過主內存數據集。 它引發MemoryError或Jupyter Kernel崩潰。 但是,要處理大型數據集,您不需要Dask或Vaex。 您只需要一些獨創性 。 聽起來好得令人難以置信?

In case you’ve missed my article about Dask and Vaex with bigger than main memory datasets:

如果您錯過了我的有關Dask和Vaex的文章,而這篇文章的內容比主內存數據集還大:

When doing an analysis you usually don’t need all rows or all columns in the dataset.

執行分析時,通常不需要數據集中的所有行或所有列。

In a case, you don’t need all rows, you can read the dataset in chunks and filter unnecessary rows to reduce the memory usage:

在某種情況下,您不需要所有行,您可以按塊讀取數據集并過濾不必要的行以減少內存使用量:

iter_csv = pd.read_csv('dataset.csv', iterator=True, chunksize=1000)
df = pd.concat([chunk[chunk['field'] > constant] for chunk in iter_csv])

Reading a dataset in chunks is slower than reading it all once. I would recommend using this approach only with bigger than memory datasets.

分塊讀取數據集要比一次讀取所有數據集慢。 我建議僅對大于內存的數據集使用此方法。

In a case, you don’t need all columns, you can specify required columns with “usecols” argument when reading a dataset:

在某種情況下,不需要所有列,可以在讀取數據集時使用“ usecols”參數指定所需的列:

df = pd.read_csvsecols=['col1', 'col2'])

The great thing about these two approaches is that you can combine them.

這兩種方法的優點在于您可以將它們組合在一起。

你走之前 (Before you go)

Image for post
giphygiphy

These are a few links that might interest you:

這些鏈接可能會讓您感興趣:

- Your First Machine Learning Model in the Cloud- AI for Healthcare- Parallels Desktop 50% off- School of Autonomous Systems- Data Science Nanodegree Program- 5 lesser-known pandas tricks- How NOT to write pandas code

翻譯自: https://towardsdatascience.com/5-essential-pandas-tricks-you-didnt-know-about-2d1a5b6f2e7

魅族mx5游戲模式小熊貓

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

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

相關文章

可行性分析報告

1 引言1.1 編寫目的&#xff1a;闡明編寫可行性研究報告的目的&#xff0c;提出讀者對象。1.2 項目背景&#xff1a;應包括● 所建議開發軟件的名稱● 項目的任務提出者、開發者、用戶及實現軟件的單位● 項目與其他軟件或其他系統的關系。1.3 定義&#xff1a;列出文檔中用到的…

(Python的)__ name__中包含什么?

_名稱_變量及其在Python中的用法簡介 (An introduction to the _ _name_ _ variable and its usage in Python) You’ve most likely seen the __name__ variable when you’ve gone through Python code. Below you see an example code snippet of how it may look:通過Pytho…

畢業論文計算機附錄模板,畢業論文格式是什么,附錄又是什么?

畢業論文格式是什么&#xff0c;附錄又是什么?附錄對論文內用起到一個補充說明的作用&#xff0c;附錄應屬于論文的正文&#xff0c;有的論文需要寫明&#xff0c;有的論文可能不需要寫&#xff0c;大多數情況是不需要寫的&#xff0c;附錄的位置一般放在論文的結尾處&#xf…

文件上傳速度查詢方法

由于業務遷移&#xff0c;需要將大量文件拷貝到目標機器上的/mnt目錄&#xff0c;在拷貝過程中&#xff0c;想要查看上傳的速度&#xff0c;做法如下&#xff1a;[rootmail01 ~]# du -sh /mnt5.6G /mnt[rootmail01 ~]# watch -n1 du -sm /mnt/ #會出現下面的一屏現象 …

spring—AOP 的動態代理技術

AOP 的動態代理技術 常用的動態代理技術 JDK 代理 : 基于接口的動態代理技術 cglib 代理&#xff1a;基于父類的動態代理技術 JDK 代理 public class proxy {Testpublic void test() {final ImplDao dao new ImplDao();Dao pro (Dao) Proxy.newProxyInstance(ImplDao.cl…

非常詳細的Django使用Token(轉)

基于Token的身份驗證 在實現登錄功能的時候,正常的B/S應用都會使用cookiesession的方式來做身份驗證,后臺直接向cookie中寫數據,但是由于移動端的存在,移動端是沒有cookie機制的,所以使用token可以實現移動端和客戶端的token通信。 驗證流程 整個基于Token的驗證流程如下: 客戶…

Java中獲取完整的url

HttpServletRequest httpRequest(HttpServletRequest)request; String strBackUrl "http://" request.getServerName() //服務器地址 ":" request.getServerPort() //端口號 httpRequest.getContextPath() //項目名稱 httpRequ…

數據科學中的數據可視化

數據可視化簡介 (Introduction to Data Visualization) Data visualization is the process of creating interactive visuals to understand trends, variations, and derive meaningful insights from the data. Data visualization is used mainly for data checking and cl…

打針小說軟件測試,UPDATE注射(mysql+php)的兩個模式

一.---- 表的結構 userinfo--CREATE TABLE userinfo (groudid varchar(12) NOT NULL default 1,user varchar(12) NOT NULL default heige,pass varchar(122) NOT NULL default 123456) ENGINEMyISAM DEFAULT CHARSETlatin1;---- 導出表中的數據 userinfo--INSERT INTO userinf…

前端速成班_在此速成班中學習Go

前端速成班Learn everything you need to get started programming in Go with this crash course tutorial.通過該速成課程教程&#xff0c;學習在Go中開始編程所需的一切。 First, learn how to install a Go Programming Environment on Windows, Mac, or Linux. Then, lea…

手把手教你webpack3(6)css-loader詳細使用說明

CSS-LOADER配置詳解 前注&#xff1a; 文檔全文請查看 根目錄的文檔說明。 如果可以&#xff0c;請給本項目加【Star】和【Fork】持續關注。 有疑義請點擊這里&#xff0c;發【Issues】。 1、概述 對于一般的css文件&#xff0c;我們需要動用三個loader&#xff08;是不是覺得好…

shell遠程執行命令

1、先要配置免密登陸&#xff0c;查看上一篇免密傳輸內容 2、命令行執行少量命令&#xff1a;ssh ip "command1;command2"。例&#xff1a;ssh 172.1.1.1 "cd /home;ls" 3、腳本批量執行命令&#xff1a; #&#xff01;/bin/bash ssh ip << remotes…

Python調用C語言

Python中的ctypes模塊可能是Python調用C方法中最簡單的一種。ctypes模塊提供了和C語言兼容的數據類型和函數來加載dll文件&#xff0c;因此在調用時不需對源文件做任何的修改。也正是如此奠定了這種方法的簡單性。 示例如下 實現兩數求和的C代碼&#xff0c;保存為add.c //samp…

多重線性回歸 多元線性回歸_了解多元線性回歸

多重線性回歸 多元線性回歸Video Link影片連結 We have taken a look at Simple Linear Regression in Episode 4.1 where we had one variable x to predict y, but what if now we have multiple variables, not just x, but x1,x2, x3 … to predict y — how would we app…

tp703n怎么做無線打印服務器,TP-Link TL-WR703N無線路由器無線AP模式怎么設置

TP-Link TL-WR703N無線路由器配置簡單&#xff0c;不過對于沒有網絡基礎的用戶來說&#xff0c;完成路由器的安裝和無線AP模式的設置&#xff0c;仍然有一定的困難&#xff0c;本文學習啦小編主要介紹TP-Link TL-WR703N無線路由器無線AP模式的設置方法!TP-Link TL-WR703N無線路…

unity 克隆_使用Unity開發Portal游戲克隆

unity 克隆Learn game development principles by coding a Portal-like game using Unity and C#. The principles you learn in this lecture from Colton Ogden can apply to any programming language and any game.通過使用Unity和C&#xff03;編寫類似于Portal的游戲來學…

swift基礎學習(八)

####1.主要用到的知識點 CAGradientLayer 處理漸變色AVAudioPlayer 音頻播放Timer 定時器CABasicAnimation 動畫#####2.效果圖 ####3.代碼 import UIKit import AVFoundationclass ViewController: UIViewController, AVAudioPlayerDelegate {var gradientLayer: CAGradientLay…

pandas之groupby分組與pivot_table透視

一、groupby 類似excel的數據透視表&#xff0c;一般是按照行進行分組&#xff0c;使用方法如下。 df.groupby(byNone, axis0, levelNone, as_indexTrue, sortTrue, group_keysTrue,squeezeFalse, observedFalse, **kwargs) 分組得到的直接結果是一個DataFrameGroupBy對象。 df…

js能否打印服務器端文檔,js打印遠程服務器文件

js打印遠程服務器文件 內容精選換一換對于密碼鑒權方式創建的Windows 2012彈性云服務器&#xff0c;使用初始密碼以MSTSC方式登錄時&#xff0c;登錄失敗&#xff0c;系統顯示“第一次登錄之前&#xff0c;你必須更改密碼。請更新密碼&#xff0c;或者與系統管理員或技術支持聯…

spring—JdbcTemplate使用

JdbcTemplate基本使用 01-JdbcTemplate基本使用-概述(了解) JdbcTemplate是spring框架中提供的一個對象&#xff0c;是對原始繁瑣的Jdbc API對象的簡單封裝。spring框架為我們提供了很多的操作模板類。例如&#xff1a;操作關系型數據的JdbcTemplate和HibernateTemplate&…