AGG

Pandas窗口函数         

一世执手 提交于 2020-04-06 01:55:10
概念 为了处理数字数据,Pandas提供了几个变体,如滚动,展开和指数移动窗口统计的权重。 其中包括总和,均值,中位数,方差,协方差,相关性等; 所谓窗口,就是将某个点的取值扩大到包含这个点的一段区间,用区间来进行判断 移动窗口就是窗口向一端滑行,默认是从右往左,每次滑行并不是区间整块的滑行,而是一个单位一个单位的滑行; 窗口函数主要用于通过平滑曲线来以图形方式查找数据内的趋势。如果日常数据中有很多变化,并且有很多数据点可用,那么采样和绘图就是一种方法,应用窗口计算并在结果上绘制图形是另一种方法。 通过这些方法,可以平滑曲线或趋势。 rolling() 这个函数可以应用于一系列数据。指定window=n参数并在其上应用适当的统计函数。 DataFrame.rolling(window, min_periods=None, center=False, win_type=None, on=None, axis=0, closed=None) 参数说明 window:表示时间窗的大小,有两种形式:1)使用数值int,则表示观测值的数量,即向前几个数据;2)也可以使用offset类型,这种类型较复杂,使用场景较少,此处暂不做介绍; min_periods:每个窗口最少包含的观测值数量,小于这个值的窗口结果为NA。值可以是int,默认None。offset情况下,默认为1; center:

PostGresql/PG 聚合函数处理

落花浮王杯 提交于 2020-02-28 05:07:42
array_to_string--将sql中的数组转为字符串 ARRAY_AGG--将sql中的数据转为数组处理 以下给大家一个简单的例子即可体会: 1.需求 2.数据库中原数据 3.sql的写法,以及运行结果 作者:那钱有着落吗 链接:https://www.jianshu.com/p/b5d1fd38e161 来源:简书 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 来源: oschina 链接: https://my.oschina.net/boonya/blog/3162919

pandas数据分类Category与cut

余生长醉 提交于 2020-01-07 01:24:09
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> cut cut( x, bins, right=True, labels=None, retbins=False, precision=3, include_lowest=False, duplicates="raise", ) 参数 说明 x 待分类数据 bins 分类方式、int、数组、IntervalIndex right 是否包含右区间,默认True labels 给分类标签 retbins 是否返回分类区间,默认False precision 精度 include_lowest 是否包含左区间,默认False duplicates bins区间有重叠处理方式,'raise'抛出异常, 'drop'删除重复 简单示例 import numpy as np import pandas as pd from pandas import DataFrame SIZE = 10 np.random.seed(147258) df = DataFrame() # 生成0到30之间的数做为年龄 df['age'] = np.random.randint(1, 31, size=SIZE) # 4个字符做为名称 df['name'] = [pd.util.testing.rands(4) for i in range

在每个GROUP BY组中选择第一行?

﹥>﹥吖頭↗ 提交于 2019-12-10 21:37:07
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 顾名思义,我想选择以 GROUP BY 分组的每组行的第一行。 具体来说,如果我有一个如下的 purchases 表: SELECT * FROM purchases; 我的输出: id | customer | total ---+----------+------ 1 | Joe | 5 2 | Sally | 3 3 | Joe | 2 4 | Sally | 1 我想查询每个 customer 购买的最大商品的 id ( total )。 像这样: SELECT FIRST(id), customer, FIRST(total) FROM purchases GROUP BY customer ORDER BY total DESC; 预期产量: FIRST(id) | customer | FIRST(total) ----------+----------+------------- 1 | Joe | 5 2 | Sally | 3 #1楼 由于存在SubQ,该解决方案不是十分有效,正如Erwin指出的那样 select * from purchases p1 where total in (select max(total) from purchases where p1.customer

聊聊storm的AggregateProcessor的execute及finishBatch方法

二次信任 提交于 2019-12-03 13:41:02
序 本文主要研究一下storm的AggregateProcessor的execute及finishBatch方法 实例 TridentTopology topology = new TridentTopology(); topology.newStream("spout1", spout) .groupBy(new Fields("user")) .aggregate(new Fields("user","score"),new UserCountAggregator(),new Fields("val")) .toStream() .parallelismHint(1) .each(new Fields("val"),new PrintEachFunc(),new Fields()); TridentBoltExecutor storm-core-1.2.2-sources.jar!/org/apache/storm/trident/topology/TridentBoltExecutor.java private void checkFinish(TrackedBatch tracked, Tuple tuple, TupleType type) { if(tracked.failed) { failBatch(tracked); _collector.fail(tuple);

Java描述设计模式(13):迭代器模式

对着背影说爱祢 提交于 2019-11-30 11:15:37
本文源码: GitHub·点这里 || GitEE·点这里 一、迭代器模式 1、基础概念 迭代器模式又叫游标模式,是对象的行为模式。迭代器模式可以顺序地访问一个聚集中的元素而不必暴露聚集的内部表象。 2、模式图解 3、核心角色 Iterator:迭代器角色 此抽象角色定义出遍历元素所需的接口。 ConcreteIterator:具体迭代器角色 此角色实现了Iterator接口,并保持迭代过程中的游标位置。 Aggregate:聚集角色 此抽象角色给出创建迭代器(Iterator)对象的接口。 ConcreteAggregate:具体聚集角色 聚合持有对象集合,提供返回迭代器的方法,可以正确遍历该集合。 Client:客户端角色 持有对聚集及其迭代器对象的引用,调用迭代器对象的迭代接口。 4、源码案例 public class C02_Iterator { public static void main(String[] args) { Object[] objArray = {"one","two","three","four","five"}; Aggregate aggregate = new ConcreteAggregate(objArray); Iterator iterator = aggregate.createIterator(); while (!iterator

聊聊storm trident的operations

自作多情 提交于 2019-11-29 20:47:55
序 本文主要研究一下storm trident的operations function filter projection Function storm-core-1.2.2-sources.jar!/org/apache/storm/trident/operation/Function.java public interface Function extends EachOperation { /** * Performs the function logic on an individual tuple and emits 0 or more tuples. * * @param tuple The incoming tuple * @param collector A collector instance that can be used to emit tuples */ void execute(TridentTuple tuple, TridentCollector collector); } Function定义了execute方法,它发射的字段会追加到input tuple中 Filter storm-core-1.2.2-sources.jar!/org/apache/storm/trident/operation/Filter.java public

服务器使用matplotlib画图

浪子不回头ぞ 提交于 2019-11-28 12:12:40
服务器中由于只有命令行界面,因此无法显示图像,这样会导致python直接使用matplotlib画图出错,因此需要做如下修改,有两种方法 方法一 这种方法需要使用的时候每次都引入,就是在python引入matplotlib.pyplot包之前写入 import matplotlib as mplmpl.use('Agg') import matplotlib.pyplot #如果不在这个之前会出错 方法二 这种是一个永久性的方法,在linux下新建~/.config/matplotlib/matplotlibrc,添加代码 backend : Agg 来源: oschina 链接: https://my.oschina.net/u/1046919/blog/2962247