Python pandas unique value ignoring NaN
Define a function: def unique_non_null(s): return s.dropna().unique() Then use it in the aggregation: df.groupby(‘b’).agg({ ‘a’: [‘min’, ‘max’, unique_non_null], ‘c’: [‘first’, ‘last’, unique_non_null] })
Define a function: def unique_non_null(s): return s.dropna().unique() Then use it in the aggregation: df.groupby(‘b’).agg({ ‘a’: [‘min’, ‘max’, unique_non_null], ‘c’: [‘first’, ‘last’, unique_non_null] })
You could define a custom model field derived from models.CharField. This field could check for duplicate values, ignoring the case. Custom fields documentation is here http://docs.djangoproject.com/en/dev/howto/custom-model-fields/ Look at http://code.djangoproject.com/browser/django/trunk/django/db/models/fields/files.py for an example of how to create a custom field by subclassing an existing field. You could use the citext module of PostgreSQL https://www.postgresql.org/docs/current/static/citext.html If you … Read more
Know your Array#product: a = [[‘1′,’2’],[‘a’,’b’],[‘x’,’y’]] a.first.product(*a[1..-1]).map(&:join)
Both NEWID() and NEWSEQUENTIALID() give globally unique values of type uniqueidentifier. NEWID() involves random activity, thus the next value is unpredictable, and it’s slower to execute. NEWSEQUENTIALID() doesn’t involve random activity, thus the next generated value can be predicted (not easily!) and executes faster than NEWID(). So, if you’re not concerned about the next value … Read more
For C/C++: #include <IOKit/IOKitLib.h> void get_platform_uuid(char * buf, int bufSize) { io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(kIOMasterPortDefault, “IOService:/”); CFStringRef uuidCf = (CFStringRef) IORegistryEntryCreateCFProperty(ioRegistryRoot, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0); IOObjectRelease(ioRegistryRoot); CFStringGetCString(uuidCf, buf, bufSize, kCFStringEncodingMacRoman); CFRelease(uuidCf); }
UPDATE: Thanks to @Ahito: In : list(set(x).symmetric_difference(set(f))) Out: [33, 2, 22, 11, 44] This article has a neat diagram that explains what the symmetric difference does. OLD answer: Using this piece of Python’s documentation on sets: >>> # Demonstrate set operations on unique letters from two words … >>> a = set(‘abracadabra’) >>> b = … Read more
This is a pretty typical example of a problem involving combinatorics. There are exactly 9⋅8⋅7⋅6⋅5⋅4⋅3⋅2⋅1 = 9! = 362880 nine-digit decimal numbers, where each digit occurs exactly once, and zero is not used at all. This is because there are nine possibilities for the first digit, eight for the second, and so on, since each … Read more
Probably not the most elegant of solutions, and the performance of IN may suffer on larger tables. The nested query gets the minimum Birthyear for each city. Only records who have this Birthyear are matched in the outer query. Ordering by age then limiting to 3 results gets you the 3 oldest people who are … Read more
While the following addresses multiple null values, it does not address any “issues” associated with such a design, other than possible database/SQL portability – as such, it should probably not be considered an answer, and is left here merely for reference. This is actually covered in the SQLite FAQ. It is a design choice – … Read more