博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
熊猫作弊表(通过yhat)
阅读量:2529 次
发布时间:2019-05-11

本文共 1941 字,大约阅读时间需要 6 分钟。

pandas cheat sheetThe folks over at
just released a cheat sheet for pandas.  You can download the cheat sheet in PDF for .

的人们刚刚发布了熊猫的备忘单。 您可以在下载PDF备忘单。

There’s a couple important functions that I use all the time missing from their cheat sheet (actually….there are a lot of things missing, but its a great starter cheat sheet).

我的备忘单一直缺少一些重要的功能(实际上……有很多东西遗失,但它是一个很棒的入门备忘单)。

A few things that I use all the time with pandas dataframes that are worth collecting in one place are provided below.

下面提供了我一直在使用的一些值得在一个地方收集的pandas数据框的注意事项。

Renaming columns in a pandas dataframe:

重命名熊猫数据框中的列:

df.rename(columns={'col1': 'Column_1', 'col2': 'Column_2'}, inplace=True)

Iterating over a pandas dataframe:

遍历熊猫数据框:

for index, row in df.iterrows(): * DO STUFF

Splitting pandas dataframe into chunks:

将pandas数据框拆分为多个块:

The function plus the function call will split a pandas dataframe (or list for that matter) into NUM_CHUNKS chunks. I use this often when working with the multiprocessing libary.

函数加上函数调用会将熊猫数据框(或相关列表)拆分为NUM_CHUNKS个块。 在使用多处理库时,我经常使用它。

# This function creates chunks and returns themdef chunkify(lst,n):    return [ lst[i::n] for i in xrange(n) ]chunks = chunkify(df, NUMCHUNKS)

Accessing the value of a specific cell:

访问特定单元格的值:

This will give you the value of the last row’s “COLUMN” cell.  This may not be the ‘best’ way to do it, but it gets the value

这将为您提供最后一行的“ COLUMN”单元格的值。 这可能不是实现此目标的“最佳”方法,但它可以带来价值

df.COLUMN.tail(1).iloc[0]

Getting rows matching a condition:

获取符合条件的行:

The below will get all rows in a pandas dataframe that match the criteria.  In addition to finding equality, you can do all the logical operators.

下面将获取熊猫数据框中符合条件的所有行。 除了寻找相等性,您还可以执行所有逻辑运算符。

df[df.COLUMN == Criteria]

Getting rows matching multiple conditions:

获取符合多个条件的行:

This gets rows that match a criteria in COLUMN1 and those that match another criteria in COLUMN2

这将获得与COLUMN1中的条件匹配的行以及与COLUMN2中的另一个条件匹配的行

 df[(df.COLUMN1 == Criteria) & (df.COLUMN2 == Criteria_2) ]

翻译自:

转载地址:http://dtqwd.baihongyu.com/

你可能感兴趣的文章
生成商户订单号/退款单号
查看>>
git使用——分支
查看>>
selenium之多线程启动grid分布式测试框架封装(一)
查看>>
突然的伤感
查看>>
Objective-C 链式编程思想
查看>>
开通了一个微信公众账号,主要想分享一些自己对于行业、技术和产品的思考以及收录精彩内容给读者...
查看>>
留言板
查看>>
c#$用法
查看>>
js通过as完成socket通信
查看>>
关于我书里提到的“挂多个类,使用类的组合”的一些补充
查看>>
JavaScrip中的循环语句
查看>>
IntelliJ IDEA和Webstorm 的下载安装、注册码(永久有效)
查看>>
停止使用非版本控制的可执行代码
查看>>
Php5.3的lambda函数以及closure(闭包)
查看>>
inotify监测实例
查看>>
C#程序如何把窗体文件从从一个项目中复制到另一个项目
查看>>
Android金背大刀之ToggleButton之稍息立正
查看>>
使用Android OpenGL ES 2.0绘图之六:响应触摸事件
查看>>
Swift之?和!
查看>>
php单元测试到底是什么东西呢?
查看>>