How can I reverse a Java 8 stream and generate a decrementing IntStream of values?

For the specific question of generating a reverse IntStream, try something like this: static IntStream revRange(int from, int to) { return IntStream.range(from, to) .map(i -> to – i + from – 1); } This avoids boxing and sorting. For the general question of how to reverse a stream of any type, I don’t know of … Read more

How to sort a pandas dataFrame by two or more columns?

As of the 0.17.0 release, the sort method was deprecated in favor of sort_values. sort was completely removed in the 0.20.0 release. The arguments (and results) remain the same: df.sort_values([‘a’, ‘b’], ascending=[True, False]) You can use the ascending argument of sort: df.sort([‘a’, ‘b’], ascending=[True, False]) For example: In [11]: df1 = pd.DataFrame(np.random.randint(1, 5, (10,2)), columns=[‘a’,’b’]) … Read more

In-place sort_values in pandas what does it exactly mean?

Here an example. df1 will hold sorted dataframe and df will be intact import pandas as pd from datetime import datetime as dt df = pd.DataFrame(data=[22,22,3], index=[dt(2016, 11, 10, 0), dt(2016, 11, 10, 13), dt(2016, 11, 13, 5)], columns=[‘foo’]) df1 = df.sort_values(by=’foo’) print(df, df1) In the case below, df will hold sorted values import pandas … Read more

Sorting a List in parallel without creating a temporary array in Java 8

There doesn’t appear to be any straightforward way to sort a List in parallel in Java 8. I don’t think this is fundamentally difficult; it looks more like an oversight to me. The difficulty with a hypothetical Collections.parallelSort(list, cmp) is that the Collections implementation knows nothing about the list’s implementation or its internal organization. This … Read more

SQL Listing all column names alphabetically

This generates a query with all columns ordered alphabetically in the select statement. DECLARE @QUERY VARCHAR(2000) DECLARE @TABLENAME VARCHAR(50) = ‘<YOU_TABLE>’ SET @QUERY = ‘SELECT ‘ SELECT @QUERY = @QUERY + Column_name + ‘, ‘ FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @TABLENAME ORDER BY Column_name SET @QUERY = LEFT(@QUERY, LEN(@QUERY) – 4) + ‘ FROM ‘+ … Read more

Custom sorting on values in a data-sort attribute with Jquery Datatables

You can use data-order attr, for example <table class=”table table-bordered table-hover”> <thead> <tr> <th>Date</th> <th>Count</th> </tr> </thead> <tbody> <?php $count = 0; foreach($users as $user) {?> <tr> <td data-order=”<?php echo $count ?>”> <?php echo $user[‘createdDate’]; ?> </td> <td> <?php echo $user[‘count’]; ?> </td> </tr> <?php $count++; }?> <tr> <td data-order=”999999999999999999999999999″> <!–always last–> Total </td> <td> … Read more

How to calculate time difference by group using pandas?

You can use sort_values with groupby and aggregating diff: df[‘diff’] = df.sort_values([‘id’,’time’]).groupby(‘id’)[‘time’].diff() print (df) id time diff 0 A 2016-11-25 16:32:17 NaT 1 A 2016-11-25 16:36:04 00:00:35 2 A 2016-11-25 16:35:29 00:03:12 3 B 2016-11-25 16:35:24 NaT 4 B 2016-11-25 16:35:46 00:00:22 If need remove rows with NaT in column diff use dropna: df = … Read more