How to get the last element of an array in PostgreSQL?
For any array “arr”, to fetch the last element of array arr use SELECT arr[array_upper(arr, 1)];
For any array “arr”, to fetch the last element of array arr use SELECT arr[array_upper(arr, 1)];
With ES6 destructuring you can do const index = […el.parentElement.children].indexOf(el) or const index = Array.from(el.parentElement.children).indexOf(el) or ES5 version var index = Array.prototype.slice.call(el.parentElement.children).indexOf(el)
Storing enum values in MongoDB as strings is perfectly fine, and yes, if you index the field I’d expect the performance to be comparable to indexed integer queries. It’s certainly more expressive than using integers. The only real downside is that they’ll take more space if your enum strings are somewhat long, but that’s a … Read more
If your data are unique, you should create a UNIQUE index on them. This implies no additional overhead and affects optimizer’s decisions in certain cases so that it can choose a better algorithm. In SQL Server and in PostgreSQL, for instance, if you sort on a UNIQUE key, the optimizer ignores the ORDER BY clauses … Read more
A better representation of a bitmap index, is if given the sample above: Identifier Gender RowID 1 Female R1 2 Male R2 3 Male R3 4 Unspecified R4 5 Female R5 the a bitmap index on the gender column would (conceptually) look like this: Gender R1 R2 R3 R4 R5 Female 1 0 0 0 … Read more
There’s a general consensus that you should reorganize (“defragment”) your indices as soon as index fragmentation reaches more than 5 (sometimes 10%), and you should rebuild them completely when it goes beyond 30% (at least that’s the numbers I’ve heard advocated in a lot of places). Michelle Ufford (a.k.a. “SQL Fool”) has an automated index … Read more
Just use a traditional for loop: for (int i = 0; i < yourArrayList.size(); i ++) { // i is the index // yourArrayList.get(i) is the element }
This approach uses .groupby() and .ngroup() (new in Pandas 0.20.2) to create the id column: df[‘id’] = df.groupby([‘LastName’,’FirstName’]).ngroup() >>> df First Second id 0 Tom Jones 0 1 Tom Jones 0 2 David Smith 1 3 Alex Thompson 2 4 Alex Thompson 2 I checked timings and, for the small dataset in this example, Alexander’s … Read more
>>> [i for i,v in enumerate(a) if v > 4] [4, 5, 6, 7, 8] enumerate returns the index and value of each item in an array. So if the value v is greater than 4, include the index i in the new array. Or you can just modify your list in place and exclude … Read more
reset_index by default does not modify the DataFrame; it returns a new DataFrame with the reset index. If you want to modify the original, use the inplace argument: df.reset_index(drop=True, inplace=True). Alternatively, assign the result of reset_index by doing df = df.reset_index(drop=True).