魅族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)

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)]

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)

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

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'])

By

通过

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

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()

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

如果我们想计算10个分位数而不是3个分位数怎么办?

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

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

4.使用正则表达式进行文本搜索 (4. Text search with regex)

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)

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)

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.taodudu.cc/news/show-997553.html

相关文章:

  • 数据科学中的数据可视化
  • 多重线性回归 多元线性回归_了解多元线性回归
  • 如何使用Python处理丢失的数据
  • 为什么印度盛产码农_印度农产品价格的时间序列分析
  • tukey检测_回到数据分析的未来:Tukey真空度的整洁实现
  • 到2025年将保持不变的热门流行技术
  • 马尔科夫链蒙特卡洛_蒙特卡洛·马可夫链
  • 数据分布策略_有效数据项目的三种策略
  • 密度聚类dbscan_DBSCAN —基于密度的聚类方法的演练
  • 从完整的新手到通过TensorFlow开发人员证书考试
  • 移动平均线ma分析_使用动态移动平均线构建交互式库存量和价格分析图
  • 静态变数和非静态变数_统计资料:了解变数
  • 不知道输入何时停止_知道何时停止
  • 掌握大数据数据分析师吗?_要掌握您的数据吗? 这就是为什么您应该关心元数据的原因...
  • 微信支付商业版 结算周期_了解商业周期
  • mfcc中的fft操作_简化音频数据:FFT,STFT和MFCC
  • r语言怎么以第二列绘制线图_用卫星图像绘制世界海岸线图-第二部分
  • rcp rapido_Rapido使用数据改善乘车调度
  • 飞机上的氧气面罩有什么用_第2部分—另一个面罩检测器……(
  • 数字经济的核心是对大数据_大数据崛起为数字世界的核心润滑剂
  • azure第一个月_MLOps:两个Azure管道的故事
  • 编译原理 数据流方程_数据科学中最可悲的方程式
  • 解决朋友圈压缩_朋友中最有趣的朋友[已解决]
  • pymc3 贝叶斯线性回归_使用PyMC3进行贝叶斯媒体混合建模,带来乐趣和收益
  • ols线性回归_普通最小二乘[OLS]方法使用于机器学习的简单线性回归变得容易
  • Amazon Personalize:帮助释放精益数字业务的高级推荐解决方案的功能
  • 西雅图治安_数据科学家对西雅图住宿业务的分析
  • 创意产品 分析_使用联合分析来发展创意
  • 多层感知机 深度神经网络_使用深度神经网络和合同感知损失的能源产量预测...
  • 使用Matplotlib Numpy Pandas构想泰坦尼克号高潮

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

  1. 魅族mx5游戏模式小熊猫_熊猫主地图在5分钟内套用和套用

    魅族mx5游戏模式小熊猫 Pandas library has two main data structures which are DataFrame and Series. There are m ...

  2. 那些你所不知道的arXiv使用技巧

    作者:Tom Hardy Date:2020-12-23 来源:那些你所不知道的arXiv使用技巧

  3. 你所不知道的模块调试技巧 - npm link #17

    你所不知道的模块调试技巧 - npm link #17 1. 背景 node 应用开发中,我们不可避免的需要使用或拆分为 npm 模块,经常遇到的一个问题是: 新开发或修改的 npm 模块,如何在项目 ...

  4. 你可能不知道的 CSS 阴影技巧与细节

    关于 CSS 阴影,之前已经有写过一篇,box-shadow 与 filter:drop-shadow 详解及奇技淫巧[1],介绍了一些关于 box-shadow 的用法. 最近一个新的项目,CSS- ...

  5. axure中出现小手_你所不知道的15个Axure使用技巧

    Axure 6.5已于4月18日发布,可直到上周我才发现,于是赶紧下载升级.等待下载的过程中,闲来无聊跑去看了Axure的版本历史,又浏览了一下官方的使用教程,忽然发现Axure竟如此博大精深,自己平 ...

  6. 酷炫时钟_您不知道的11种酷炫形状

    酷炫时钟 Whether it's in nature, architecture or the products we use, cool shapes are everywhere around ...

  7. python 函数调用 不允许关键字参数_你所不知道的Python|函数参数的演进之路

    原标题:你所不知道的Python|函数参数的演进之路 函数参数处理机制是Python中一个非常重要的知识点,随着Python的演进,参数处理机制的灵活性和丰富性也在不断增加,使得我们不仅可以写出简化的 ...

  8. 那些你可能不知道的谷歌浏览器实用技巧

    苏生不惑第155 篇原创文章,将本公众号设为星标,第一时间看最新文章. 关于谷歌浏览器之前写过以下文章: 实用油猴脚本推荐,让你的谷歌浏览器更强大 Chrome 浏览器扩展神器油猴 请停用以开发者模式 ...

  9. 14个你可能不知道的JavaScript调试技巧

    以更快的速度和更高的效率来调试JavaScript 熟悉工具可以让工具在工作中发挥出更大的作用.尽管江湖传言 JavaScript 很难调试,但如果你掌握了几个技巧,就能用很少的时间来解决错误和bug ...

最新文章

  1. 最新 crtmpserver 源码的获取方法
  2. 数据类型中的零碎基础知识
  3. 电网机巡智能管控平台渗透测试经历
  4. Windows 11 用户“怒了” :微软发推炫耀 3D 海龟表情包引争议
  5. 【正则表达式】值匹配汉字的正字表达式
  6. 计算机相关概念总结(3)
  7. linux忘记root密码的两种修改方法
  8. Imc连环画《红楼梦》
  9. Spark on Yarn 模式编写workcount实例
  10. boost::contract模块实现ifdef宏功能测试程序
  11. “反应快”的程序猿更优秀吗?
  12. MySQL---InnoDB引擎隔离级别详解
  13. linux qt3编译出错,Linux下编译Qt 5版本源码
  14. P2:图像分类:KNN与线性分类器
  15. 常用的3款光学仿真软件分析---来源网络
  16. 内含干货PPT下载|一站式数据管理DMS关键技术解读
  17. 那些值得推荐的Superbrowser跨境工具
  18. NoteExpress样式制作手册
  19. RMAN-06004、RMAN-20011
  20. 刨根系列之volatile详解 (二)

热门文章

  1. access ole 对象 最大长度_Redis 数据结构和对象系统,有这 12 张图就够了!
  2. Dinosaur Run - Dinosaur world Games
  3. ZOJ3385 - Hanami Party (贪心)
  4. 微信客户端<->腾讯微信服务器<->开发者服务器
  5. 让 C#智能注释时允许换行
  6. Lecture 17 Shortest Paths I
  7. 3.19PMP试题每日一题
  8. 让自己的头脑极度开放
  9. 【Android Studio安装部署系列】目录
  10. I/O多路转接之poll,epoll