魅族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.mzph.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&…