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

news/2025/2/23 2:08:29/

魅族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
Giphy Giphy的 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
giphy giphy

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
Giphy Giphy的 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
Giphy Giphy的 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
giphy giphy

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
giphy giphy

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.ppmy.cn/news/436122.html

相关文章

魅族 android9.0,魅族Flyme9含内测答案最新版-魅族Flyme9.0内测版v9.0 安卓版-腾飞网...

魅族Flyme9.0内测版是魅族系统进行的一次重大更新&#xff0c;在这次更新中各种界面图标还有系统功能都进行了全面调整&#xff0c;用户可以见到一个完全不一样的魅族Flyme&#xff0c;好奇的小伙伴可以下载我们提供的最新内测版看看&#xff01; 魅族Flyme9内测版特色 1、Flym…

可以边玩游戏边学编程的手游盘点

1.异常/Exception 为虚拟世界中的机器人编写AI程序&#xff0c;帮助他们打败敌人&#xff0c;难度逐渐加大&#xff0c;后期需要为多个不同类型的机器人编写行为模式打配合战。 2.人力资源机 Human Resource Machine 扮演刚开始工作的小职员&#xff0c;通过编程来实现办公自…

漫谈手游商业游戏前端框架

今天想聊一聊手游商业游戏前端框架. 既然是前端框架,就先从选哪个引擎开始聊起吧. 技术选型 这其中有两个关键字,一是"手游", 二是"商业" . 说到"手游", 基本上引擎就定位在了 Unity. 在手游开发行业, 除了个别技术实力非常雄厚的公司,和个别…

手游平台系统怎么和游戏发行商对接?

其实&#xff0c;手游联运平台上的大部分游戏&#xff0c;都不是他们自己开发的&#xff0c;也不是他们的专属&#xff0c;其他平台也有他们的游戏。手游联运&#xff0c;就是一种与游戏公司之间的合作&#xff0c;我们称之为联运。对于手游运营商来说&#xff0c;找一家知名的…

Meizu M8 SDK开发初体验

Meizu M8 SDK开发初体验 作者&#xff1a;马宁 魅族在经历了两年多的开发后&#xff0c;M8终于上市了。能够被称为iPhone Killer&#xff0c;说明了M8有自身的优势。之前也有朋友问过我&#xff0c;会买一款M8试试吗&#xff1f;我说&#xff0c;不会&#xff0c;除非M8出SDK。…

端游及手游,游戏服务端架构,游戏研发流程

> 游戏框架&#xff0c;游戏架构&#xff0c; Lua和C# 游戏的策略&#xff08;规则 交互等&#xff09;&#xff0c;游戏的算法&#xff0c;游戏的实时通信&#xff0c;游戏的界面绘制&#xff0c;游戏的运营等。 [Android游戏开发]游戏框架的搭建- http://www.cnblogs.com/…

主流游戏引擎分析 【端游 、页游 、手游 解析】

该分享仅供参考,目的是提升大家对游戏引擎方面的一些认知。文档中部分内容收集于互联网,若有内容不准确,还请告知。 关于本文PPT文档:github 一、介绍 游戏引擎是指一些已编写好的可编辑电脑游戏系统或者一些互交式实时图像应用程序的核心组件。这些系统为游戏设计者提供各…

那些主流的游戏引擎分析(页游 、端游 、手游)

一、介绍 游戏引擎就是指一些已编写好的可编辑电脑游戏系统或者一些互交式实时图像应用程序的核心组件。而这些系统为游戏设计者提供各种编写游戏所需的各种工具&#xff0c;让游戏设计者能容易和快速地做出游戏程序而不用由零开始。大部分都支持多种操作系统平台&#xff0c;…