熊猫在连续的群体之间进行差异

时间:2017-07-14 13:16:09

标签: pandas diff

d = pd.DataFrame({'a':[7,6,3,4,8], 'b':['c','c','d','d','c']})
d.groupby('b')['a'].diff()

给我

0    NaN
1   -1.0
2    NaN
3    1.0
4    2.0

我需要什么

0    NaN
1   -1.0
2    NaN
3    1.0
4    NaN  

只有组内的连续值之间存在差异,因此当一个组出现在另一个组之后时,它的先前值将被忽略。

在我的示例中,上一个c值是一个新的c组。

1 个答案:

答案 0 :(得分:2)

您需要 // First create your observable Observable<OnTextChangeEvent> yourTextChangeObservable = WidgetObservable.text(yourInputText); // And create your subscription yourTextChangeSubscription = yourTextChangeObservable .debounce(YORU_TRASH_HOLD_TIME, TimeUnit.MILLISECONDS) .map(OnTextChangeEvent::text) .map(CharSequence::toString) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { // do your work here with your input } ); 连续片段

Debounce

详细

groupby