熊猫GroupBy Subtotals

时间:2018-03-08 01:34:32

标签: python pandas

所以我有一个包含时间序列的数据框,例如:

NAME, DATE, VACATION (True/False)
Eric, 1/1/12, False
Eric, 1/2/12, True
...
Bob, 4/2/12, True
Bob, 4/3/12, False

基本上我需要的是一个dict或者我可以在Jinja2中使用以下格式模板的东西

{'eric': 
    vacations: [1/2/12, ... ],
    subtotals: {
          '2012': {
                    'total': 1 
                    'perweek': [1, 0, 0, ... ] (LEN = 52, week numbers)
                    'perquarter': [1, 0, 0, 0] (LEN = 4)
                   },
          '2013': { ... }
     },
 'bob': ...
}

基本上我需要按每年每位用户的假期小计分解为每季度,每周,每季度......

是否有快速方法将其转换为dict,以便我可以使用Jinja2将其模板化出来?

我知道我可以做groupby等等......但我只能弄清楚如何每周与每季度,每年分开,所有不同的组合,然后将它们重新组装成一个字典。

有没有办法一次完成所有这些?

目前我正在做以下事情......

perweek = df.groupby(['name', 'date'].count.resample('W').count
for i in perweek.iter
  add to dict

perquarter = df.groupby(['name', 'date']).count.resample.count
for i in perquarter.iter
  add to dict

peryear ... etc

基本上我分组,然后计数,然后重新采样...然后迭代这些并将它们添加到dict。对我想要的每个重采样做同样的事情。它的工作原理......我只是想知道是否有办法在没有多个迭代器的情况下完成它。

1 个答案:

答案 0 :(得分:1)

我有一个复杂的解决方案。

the report generating property m using are given below:
jmeter.reportgenerator.exclude_tc_from_top5_errors_by_sampler=true


jmeter.reportgenerator.graph.bytesThroughputOverTime.exclude_controllers=true
jmeter.reportgenerator.graph.bytesThroughputOverTime.property.set_granularity=${jmeter.reportgenerator.overall_granularity}

# Response Time Over Time graph definition
jmeter.reportgenerator.graph.responseTimesOverTime.classname=org.apache.jmeter.report.processor.graph.impl.ResponseTimeOverTimeGraphConsumer
jmeter.reportgenerator.graph.responseTimesOverTime.title=Response Time Over Time
jmeter.reportgenerator.graph.responseTimesOverTime.property.set_granularity=${jmeter.reportgenerator.overall_granularity}

# Percentiles Response Times over time
jmeter.reportgenerator.graph.responseTimePercentilesOverTime.classname=org.apache.jmeter.report.processor.graph.impl.ResponseTimePercentilesOverTimeGraphConsumer
jmeter.reportgenerator.graph.responseTimePercentilesOverTime.title Response Time Percentiles Over Time (successful requests only)
jmeter.reportgenerator.graph.responseTimePercentilesOverTime.property.set_granularity=${jmeter.reportgenerator.overall_granularity}

# Synthetic Response Time Distribution
jmeter.reportgenerator.graph.syntheticResponseTimeDistribution.classname=org.apache.jmeter.report.processor.graph.impl.SyntheticResponseTimeDistributionGraphConsumer
jmeter.reportgenerator.graph.syntheticResponseTimeDistribution.title=Synthetic Response Times Distribution
jmeter.reportgenerator.graph.syntheticResponseTimeDistribution.exclude_controllers=true
jmeter.reportgenerator.graph.syntheticResponseTimeDistribution.property.set_satisfied_threshold=${jmeter.reportgenerator.apdex_satisfied_threshold}
jmeter.reportgenerator.graph.syntheticResponseTimeDistribution.property.set_tolerated_threshold=${jmeter.reportgenerator.apdex_tolerated_threshold}

# Latencies Over Time graph definition
jmeter.reportgenerator.graph.latenciesOverTime.classname=org.apache.jmeter.report.processor.graph.impl.LatencyOverTimeGraphConsumer
jmeter.reportgenerator.graph.latenciesOverTime.title=Latencies Over Time
jmeter.reportgenerator.graph.latenciesOverTime.property.set_granularity=${jmeter.reportgenerator.overall_granularity}

# Connect Time Over Time graph definition
jmeter.reportgenerator.graph.connectTimeOverTime.classname=org.apache.jmeter.report.processor.graph.impl.ConnectTimeOverTimeGraphConsumer
jmeter.reportgenerator.graph.connectTimeOverTime.title=Connect Time Over Time
jmeter.reportgenerator.graph.connectTimeOverTime.property.set_granularity=${jmeter.reportgenerator.overall_granularity}

# Response Time Vs Request graph definition
jmeter.reportgenerator.graph.responseTimeVsRequest.classname=org.apache.jmeter.report.processor.graph.impl.ResponseTimeVSRequestGraphConsumer
jmeter.reportgenerator.graph.responseTimeVsRequest.title=Response Time Vs Request
jmeter.reportgenerator.graph.responseTimeVsRequest.exclude_controllers=true
jmeter.reportgenerator.graph.responseTimeVsRequest.property.set_granularity=${jmeter.reportgenerator.overall_granularity}

# Latencies Vs Request graph definition
jmeter.reportgenerator.graph.latencyVsRequest.classname=org.apache.jmeter.report.processor.graph.impl.LatencyVSRequestGraphConsumer
jmeter.reportgenerator.graph.latencyVsRequest.title=Latencies Vs Request
jmeter.reportgenerator.graph.latencyVsRequest.exclude_controllers=true
jmeter.reportgenerator.graph.latencyVsRequest.property.set_granularity=${jmeter.reportgenerator.overall_granularity}

# Hits Per Second graph definition
jmeter.reportgenerator.graph.hitsPerSecond.classname=org.apache.jmeter.report.processor.graph.impl.HitsPerSecondGraphConsumer
jmeter.reportgenerator.graph.hitsPerSecond.title=Hits Per Second
jmeter.reportgenerator.graph.hitsPerSecond.exclude_controllers=true
jmeter.reportgenerator.graph.hitsPerSecond.property.set_granularity=${jmeter.reportgenerator.overall_granularity}

# Codes Per Second graph definition
jmeter.reportgenerator.graph.codesPerSecond.classname=org.apache.jmeter.report.processor.graph.impl.CodesPerSecondGraphConsumer
jmeter.reportgenerator.graph.codesPerSecond.title=Codes Per Second
jmeter.reportgenerator.graph.codesPerSecond.exclude_controllers=true
jmeter.reportgenerator.graph.codesPerSecond.property.set_granularity=${jmeter.reportgenerator.overall_granularity}

# Transactions Per Second graph definition
jmeter.reportgenerator.graph.transactionsPerSecond.classname=org.apache.jmeter.report.processor.graph.impl.TransactionsPerSecondGraphConsumer
jmeter.reportgenerator.graph.transactionsPerSecond.title=Transactions Per Second
jmeter.reportgenerator.graph.transactionsPerSecond.property.set_granularity=${jmeter.reportgenerator.overall_granularity}