How to constuct a column of data frame recursively with pandas-python?

You can use: df.loc[0, ‘diff’] = df.loc[0, ‘val’] * 0.4 for i in range(1, len(df)): df.loc[i, ‘diff’] = (df.loc[i, ‘val’] – df.loc[i-1, ‘diff’]) * 0.4 + df.loc[i-1, ‘diff’] print (df) id_ val diff 0 11111 12 4.8000 1 12003 22 11.6800 2 88763 19 14.6080 3 43721 77 39.5648 The iterative nature of the calculation … Read more

PHP convert nested array to single array while concatenating keys?

Something like this: function makeNonNestedRecursive(array &$out, $key, array $in){ foreach($in as $k=>$v){ if(is_array($v)){ makeNonNestedRecursive($out, $key . $k . ‘_’, $v); }else{ $out[$key . $k] = $v; } } } function makeNonNested(array $in){ $out = array(); makeNonNestedRecursive($out, ”, $in); return $out; } // Example $fooCompressed = makeNonNested($foo);

HQL recursion, how do I do this?

You can’t do recursive queries with HQL. See this. And as stated there it is not even standard SQL. You have two options: write a vendor-specific recursive native SQL query make multiple queries. For example: // obtain the first node using your query while (currentNode.parent != null) { Query q = //create the query q.setParameter(“id”, … Read more

Python Array Rotation

You can rotate a list in place in Python by using a deque: >>> from collections import deque >>> d=deque([1,2,3,4,5]) >>> d deque([1, 2, 3, 4, 5]) >>> d.rotate(2) >>> d deque([4, 5, 1, 2, 3]) >>> d.rotate(-2) >>> d deque([1, 2, 3, 4, 5]) Or with list slices: >>> li=[1,2,3,4,5] >>> li[2:]+li[:2] [3, 4, … Read more