- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
编辑我已经修改了以下描述的部分,以阐明我所说的“功能”和“组”的含义,修正错字,并包括我尝试过的其他代码。
我的 Pandas df
有450万行和23列。下表显示了从df2
生成的df
的几行。它显示了两个组(eeskin和hduquant)和三个功能(失败,exit_status和job_number):
# report by group
group feature #_cats #_jobs rank top_value freq \
10 eeskin failed 1 6 -1 100 6
21 eeskin exit_status 1 6 -1 0 6
0 eeskin job_number 1 6 -1 4.08219e+06 6
21 hduquant exit_status 5 64 -1 37 58
11 hduquant failed 2 64 -1 0 63
1 hduquant job_number 2 64 -1 4.07192e+06 61
exits_status
可以暂时保持-1。
group feature #_cats #_jobs rank top_value freq \
10 eeskin failed 1 6 1 100 6
21 eeskin exit_status 1 6 -1 0 6
0 eeskin job_number 1 6 2 4.08219e+06 6
21 hduquant exit_status 5 64 -1 37 58
11 hduquant failed 2 64 2 0 63
1 hduquant job_number 2 64 1 4.07192e+06 61
failed
排名为1,而
job_number
排名为2。 “hdquant”对于
failed
排名2,对于
job_number
排名1。
job_number
的等级值:
if feat == 'job_number':
grouped = grouped.sort_values("#_jobs", ascending=False)
grouped['rank'] = grouped.index + 1
group feature #_cats #_jobs rank top_value freq \
10 eeskin failed 1 6 -1 100 6
21 eeskin exit_status 1 6 -1 0 6
0 eeskin job_number 1 6 2 4.08219e+06 6
21 hduquant exit_status 5 64 -1 37 58
11 hduquant failed 2 64 -1 0 63
1 hduquant job_number 2 64 1 4.07192e+06 61
feat = ['job_number', 'failed']
for f in feat:
if f == 'job_number':
grouped = grouped.sort_values("#_jobs", ascending=False)
grouped['rank'] = grouped.index + 1
elif f == 'failed': # or f == 'exit_status'
x = len(not grouped[f] == 0)
grouped['x'] = x
grouped = grouped.sort_values("x", ascending=False)
grouped['rank'] = grouped.index + 1
del grouped['x']
group feature #_cats #_jobs rank top_value freq \
10 eeskin failed 1 6 -1 100 6
21 eeskin exit_status 1 6 -1 0 6
0 eeskin job_number 1 6 -1 4.08219e+06 6
21 hduquant exit_status 5 64 -1 37 58
11 hduquant failed 2 64 -1 0 63
1 hduquant job_number 2 64 -1 4.07192e+06 61
df.loc[df.feature == 'job', 'rank'] = df.loc[df.feature == 'job', 'jobs'].rank(ascending=False)
df2.loc[df2['feature' == 'job_number'] & df2['rank']] = (df2.loc[df2['#_jobs']].rank(ascending=False))
import pandas as pd
df = pd.DataFrame([['g1', 'u1', 3902779, '2018-09-27 21:38:06', '2018-10-01 07:24:38', '2018-10-01 08:00:42', 0, 0, 'single', 1, 55696, 609865728.0, 4.0, 6.0, 0, 0, 4.0, 0, 'single', 1, 0, pd.Timedelta('3 days 09:46:32'), pd.Timedelta('00:36:04')]],
columns=['group', 'owner', 'job_number', 'submission_time', 'start_time', 'end_time', 'failed', 'exit_status', 'granted_pe', 'slots', 'task_number', 'maxvmem', 'h_data', 'h_rt', 'highp', 'exclusive', 'h_vmem', 'gpu', 'pe', 'slot', 'campus', 'wait_time', 'wtime'])
df = (df.astype(dtype={'group':'str', 'owner':'str', 'job_number':'int', 'submission_time':'datetime64[ns]', 'start_time':'datetime64[ns]', 'end_time':'datetime64[ns]', 'failed':'int', 'exit_status':'int', 'granted_pe':'str', 'slots':'int', 'task_number':'int', 'maxvmem':'float', 'h_data':'float', 'h_rt':'float', 'highp':'int', 'exclusive':'int', 'h_vmem':'float', 'gpu':'int', 'pe':'str', 'slot':'int', 'campus':'int', 'wait_time':'timedelta64[ns]', 'wtime':'timedelta64[ns]'}))
df
group owner job_number submission_time start_time end_time failed exit_status granted_pe slots task_number maxvmem h_data h_rt highp exclusive h_vmem gpu pe slot campus wait_time wtime
0 g1 u1 3902779 2018-09-27 21:38:06 2018-10-01 07:24:38 2018-10-01 08:00:42 0 0 single 1 55696 609865728.0 4.0 6.0 0 0 4.0 0 single 1 0 3 days 09:46:32 00:36:04
4080243 g50 u92 4071923 2018-10-25 02:08:14 2018-10-27 01:41:58 2018-10-27 02:08:50 0 0 shared 1 119 7.654482e+08 2.5 1.5 0 1 16.0 0 shared 1 0 1 days 23:33:44 00:26:52
4080244 g50 u92 4071922 2018-10-25 02:08:11 2018-10-27 01:46:53 2018-10-27 02:08:53 0 0 shared 1 2208 1.074463e+09 2.5 1.5 0 10 24.0 0 shared 1 0 1 days 23:38:42 00:22:00
最佳答案
您可以使用pandas .loc
来完成此操作
初始化数据帧:
df = pd.DataFrame({'group':['e','e','e','h','h','h'],
'feature':['fail', 'exit', 'job', 'exit', 'fail', 'job'],
'cats':[1, 1, 1, 5, 2, 2],
'jobs':[1, 1, 1, 64, 64, 64],
'rank':[-1, -1, -1, -1, -1, -1],
'topvalue':[100, 0, 4, 37, 0, 3.9],
'freq':[1, 1, 1, 58, 63, 61]
})
.loc
隔离排名位置,然后在分配的右侧,我们使用
.loc
隔离jobs列并使用
.rank()
函数
df.loc[df.feature == 'job', 'rank'] = df.loc[df.feature == 'job', 'jobs'].rank(ascending=False)
top_value == 0
排名保持为-1
df.loc[(df.feature == 'fail') & (df.topvalue != 0), 'rank'] = (
df.loc[(df.feature == 'fail') & (df.topvalue != 0), 'freq']).rank(ascending=True)
df.loc[(df.feature == 'fail') & (df.topvalue != 0), 'rank'] = (
df.loc[(df.feature == 'fail') & (df.topvalue != 0), 'freq']).rank(ascending=True)
关于python - pandas python根据一个或多个其他列的子集更新列A的子集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55034626/
我正在执行大型 ffdf 对象的子集,我注意到当我使用 subset.ff 时,它会生成大量 NA。我通过使用 ffwhich 尝试了另一种方法,结果要快得多,并且没有生成 NA。这是我的测试: li
我对 Prolog 有点陌生。我正在尝试编写一个函数subset(Set, Subset) 来确定Subset 是否是Set 的子集(duh)。另外,如果第二个参数没有实例化,它应该输出每个可能的子集
一、题目 给你一个整数数组 nums ,数组中的元素 互不相同 。返回该数组所有可能的子集(幂集)。 解集 不能 包含重复的子集。你可以按 任意顺序 返回解集。 二、示例 输入:nums = [1,2
我想从数据帧的操作中排除一列。当然,我可以在没有要排除的列的情况下复制数据框,但这似乎是一种解决方法。我认为必须有一种更简单的方法来进行子集化。 所以这个示例代码应该显示我在做什么。 df colMe
我有一个 SpatialPolygonsDataFrame我通过使用 readOGR 读取 shapefile 创建的在 rgdal包裹。我正在尝试使用它来使用 spsample 生成采样网格在 sp
我想解决一个简单的问题,但即使我尝试了很多不同的方法,我也找不到解决方案。我正在使用 SICStus Prolog (如果这很重要),并且我想获取列表的所有子列表/子集(我不知道哪个术语是正确的),其
我目前正在使用 shinyTable,它是 HandsonTable (https://github.com/trestletech/shinyTable) 的 shiny 兼容实现。巧合的是,我意识
我正在 Delphi 中构建一个表单,其中包含服务下拉列表和用于选择服务的附加组件网格。我获取的数据来自 API,并且我将服务的数据存储在 ADODataSet 中,如下所示: ID (integer
subset() 函数有问题。如何通过观察次数对我的数据框的一个因子进行子集化? NAME CLASS COLOR VALUE antonio
我想知道是否有任何简单的算法来比较一个散列是否是另一个散列的子集。 例如,如果 $HASH{A} = B; $HASH{B} = C; $HASH{C} = D; $HASH2{A} = B; $HA
这个问题在这里已经有了答案: Array combinations without repetition (1 个回答) 关闭 8 年前。 给定一个数组,如何在 postgresql 中找到一定大小
我有下一个程序。我应该如何在 main 中使用迭代器以显示总和为 0 的子集? 我的程序应该打印: 2 -2 5 -5 # include # include using namespace st
我正在寻找一个可以自定义的 Markdown 解析器,最好是 Javascript。特别是,我想删除使用实际 HTML 标签的选项。我尝试编辑摊牌的来源,但无法弄清楚。 Jquery 集成也很好,尽管
我有一个包含名称列表的文件(引用文件 1): Apple Bat Cat 我有另一个文件(引用文件 2),其中包含名称列表和详细信息引用: Apple bla blaa aaaaaaaaagggggg
我有两个带有排序行的文件。一个文件 (B) 是另一个文件 (A) 的子集。我想找到 A 中不在 B 中的所有行。理想情况下,我想创建一个包含这些行的文件 (C)。这在 Unix 中可能吗?我正在寻找一
我有一个包含肽序列的列的数据框,我只想保留字符串中没有内部“R”或“K”的行。 df1 <- data.frame( Peptide = c("ABCOIIJUHFSAUJHR", "AOFI
这个问题在这里已经有了答案: How to subset matrix to one column, maintain matrix data type, maintain row/column na
假设我有一个列表向量: library(tidyverse) d 2) # A tibble: 5 x 1 x 1 2 3 4 5 最佳答案 应该是 lengt
我自己从来没有运行过javadoc(无论是在命令行还是ant's javadoc task;我将使用ant)——我需要为我编写的库生成一个javadoc。 问题是我的 java 库被组织成几个包,在
假设一个多方加密方案,类似于答案:Encryption with multiple different keys? . 那是。一组键K可以用来破译密文。 有没有办法过期: K'⊆ K 这样 K \ K
我是一名优秀的程序员,十分优秀!