- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
示例数据:
| Plan | Run | Status | Tested On |
|------|----------|----------------|------------|
| P0 | Agent | Passed | 2018-08-11 |
| | Customer | Failed | 2018-08-01 |
| P1 | A | Passed | 2018-08-02 |
| | B | Untested | 2018-08-11 |
| P2 | C | Not Applicable | 2018-08-05 |
我的脚本:
msft = pd.read_excel(
"C:\\Users\\gomat\\Desktop\\Py TR\\week_06(1).xlsx")
msft = pd.pivot_table(
msft, index = ['Plan'],
values = ['Passed', 'Failed', 'Blocked', 'Not_Implemented',
'Clarification Opened', 'In Progress', 'Not Applicable' ],
columns =['Plan'],aggfunc = 'count')
msft.to_excel("C:\\Users\\gomat\\Desktop\\Py TR\\week_06.xlsx")
实际结果:
C:\Program Files (x86)\Python36-32\lib\site-packages\pandas\core\reshape\pivot.py in pivot_table(data, values, index, columns, aggfunc, fill_value, margins, dropna, margins_name)
56 for i in values:
57 if i not in data:
---> 58 raise KeyError(i)
59
60 to_filter = []
KeyError: 'Passed'
`预期结果:我需要状态中的值计数
最佳答案
您需要先按 boolean indexing
过滤或 query
:
msft = pd.read_excel("C:\\Users\\gomat\\Desktop\\Py TR\\week_06(1).xlsx")
L = ['Passed', 'Failed', 'Blocked', 'Not_Implemented', 'Clarification Opened',
'In Progress', 'Not Applicable' ]
msft = msft[msft['Status'].isin(L)]
#alternative for filtering
#msft = msft.query('Status in @L')
msft = msft.groupby(['Plan', 'Status']).size().reset_index(name='count')
print (msft)
Plan Status count
0 P0 Failed 1
1 P0 Passed 1
2 P1 Passed 1
3 P2 Not Applicable 1
msft.to_excel("C:\\Users\\gomat\\Desktop\\Py TR\\week_06.xlsx")
关于python - 如何使用 pandas.pivot_table 获取 status 中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48719253/
我有以下数据框。 df.head(30) struct_id resNum score_type_name score_value 0 4294967297 1
我是python的新手。我有以下数据框。我能够在 Excel 中旋转。 我想添加差异列(在图像中,我手动添加了它)。 区别在于B-A值。我能够使用 Python 数据透视表复制差异列和总计。下面是我的
我正在尝试在 Dask 上使用 Pivot_table 和以下数据框: date store_nbr item_nbr unit_sales year month 0
我有一个像这样的数据框: ID Sim Items 1 0.345 [7,7] 2
我想根据以下数据框制作一个数据透视表,其中包含列 sales、rep。数据透视表显示 sales 但没有 rep。当我尝试仅使用 rep 时,出现错误 DataError: No numeric ty
如下所示: date 20170307 20170308 iphone4 2 0
考虑一个数据框: df = pd.DataFrame( {'last_year': [1, 2, 3], 'next_year': [4, 5, 6]}, index=['foo',
我看到这个问题被问过多次,但其他问题的解决方案没有奏效! 我有这样的数据框 df = pd.DataFrame({ "date": ["20180920"] * 3 + ["20180921"] *
我正在使用 Pandas pivot_table在大型数据集(1000 万行,6 列)上运行。由于执行时间是最重要的,我尝试加快进程。目前处理整个数据集需要大约 8 秒,这很慢,我希望找到提高速度/性
我收到了 KeyError: "... not in index"使用pandas的pivot_table时。 这是示例代码: arrays = [['bar', 'bar', 'foo', 'foo
当将列设置为Margins=True时,pd.grouper datetime在 Pandas 数据透视表中将不起作用。这是我的代码,可以按预期工作- p = df.pivot_table(value
>>> df A B C D 0 foo one small 1 1 foo one large 2 2 foo one large 2 3 foo two sm
数据集 x y a 1 3 0 1 1 0 1 2 0 3 6 0 5 3 1 1 5 0 1 7 0 1 6 0 1 4
数据集 x y a 1 3 0 1 1 0 1 2 0 3 6 0 5 3 1 1 5 0 1 7 0 1 6 0 1 4
我有这个样本: import pandas as pd import numpy as np dic = {'name': ['j','c','q','j','c','q','j','c
我对 pandas pivot_table 有疑问。 有时,“值”列表中指定的列的顺序不匹配 In [11]: p = pivot_table(df, values=["x","y"], cols=[
我试图通过平均值、中位数、第 25 个百分位数、第 75 个百分位数、标准差来描述 A 列、B 列。 df = pd.DataFrame({'A':[1,9,3,4,6,8,2,7],
我有下表: ID Metric Level Level(% Change) Level(Diff) Index 0 2016 A 10
我有下表: In [303]: table.head() Out[303]: people weekday weekofyear 2012-01-01 119
我似乎无法弄清楚如何将每个 date_submitted 组的总列百分比添加到下面的 pandas 数据透视表中: In [177]: pass_rate_pivot date_submitted
我是一名优秀的程序员,十分优秀!