frozenset

Finding substring in pandas frozenset

烈酒焚心 提交于 2019-12-22 17:58:13
问题 I'm trying to find a substring in a frozenset, however I'm a bit out of options. My data structure is a pandas.dataframe (it's from the association_rules from the mlxtend package if you are familiar with that one) and I want to print all the rows where the antecedents (which is a frozenset) include a specific string. Sample data: print(rules[rules["antecedents"].str.contains('line', regex=False)]) However whenever I run it, I get an Empty Dataframe. When I try running only the inner function

Python: frozensets comparison

Deadly 提交于 2019-12-20 04:25:10
问题 consider the following script: # multipleSmallFrozensets is a list of 7 frozensets of differenet number of string objects multipleSmallFrozensets = [ frozenset({'YHR007C', 'YHR042W'}), frozenset({'YPL274W'}), frozenset({'YCL064C'}), frozenset({'YBR166C'}), frozenset({'YEL041W', 'YJR049C'}), frozenset({'YGL142C'}), frozenset({'YJL134W', 'YKR053C'})] # singleFrozenset is a frozenset of 3410 string objects singleFrozenset = frozenset({'YIL140W','YLR268W','YLR357W','YJL155C','YHR067W', 'YAL008W',

Set vs. frozenset performance

只谈情不闲聊 提交于 2019-12-17 22:57:14
问题 I was tinkering around with Python's set and frozenset collection types. Initially, I assumed that frozenset would provide a better lookup performance than set , as its immutable and thus could exploit the structure of the stored items. However, this does not seem to be the case, regarding the following experiment: import random import time import sys def main(n): numbers = [] for _ in xrange(n): numbers.append(random.randint(0, sys.maxint)) set_ = set(numbers) frozenset_ = frozenset(set_)

Add the empty set to a family of sets in a frozenset in python

天大地大妈咪最大 提交于 2019-12-11 04:48:20
问题 Suppose I generate a frozenset with A = frozenset(frozenset([element]) for element in [1,2,3]) And I have the empty set E = frozenset(frozenset()) Now I want to have the union of both sets: U = A | E This gives me frozenset({frozenset({2}), frozenset({3}), frozenset({1})}) this assumes, that a frozenset, containing an empty frozenset is itself empty. However, I'd like to have frozenset({frozenset({}), frozenset({2}), frozenset({3}), frozenset({1})}) So, I'd like to add the empty set

Time-complexity of checking if two frozensets are equal in Python

假如想象 提交于 2019-12-11 01:32:47
问题 Couldn't find the details of this anywhere online, when comparing two frozensets does Python iterate through the elements in one of the sets or does it check the hash values of the frozensets since frozensets are hashable? 回答1: Since the reference docs don't say anything about this, it's implementation-dependent, so there is no answer short of looking at the source code for the version of Python you're using (in your CPython distribution's Objects/setobject.c ). Looking at the source for

Apply a function pairwise on a pandas series

徘徊边缘 提交于 2019-12-10 22:25:59
问题 I've a pandas series whose elements constitute frozensets: data = {0: frozenset({'apple', 'banana'}), 1: frozenset({'apple', 'orange'}), 2: frozenset({'banana'}), 3: frozenset({'kumquat', 'orange'}), 4: frozenset({'orange'}), 5: frozenset({'orange', 'pear'}), 6: frozenset({'orange', 'pear'}), 7: frozenset({'apple', 'banana', 'pear'}), 8: frozenset({'banana', 'persimmon'}), 9: frozenset({'apple'}), 10: frozenset({'banana'}), 11: frozenset({'apple'})} tokens = pd.Series(data); tokens 0 (apple,

Finding substring in pandas frozenset

孤街浪徒 提交于 2019-12-06 07:49:09
I'm trying to find a substring in a frozenset, however I'm a bit out of options. My data structure is a pandas.dataframe (it's from the association_rules from the mlxtend package if you are familiar with that one) and I want to print all the rows where the antecedents (which is a frozenset) include a specific string. Sample data: print(rules[rules["antecedents"].str.contains('line', regex=False)]) However whenever I run it, I get an Empty Dataframe. When I try running only the inner function on my series of rules["antecedents"] , I get only False values for all entries. But why is that? adrtam

Is it safe to use frozen set as Dict key?

馋奶兔 提交于 2019-12-05 19:30:18
问题 It obviously works but are there cases where two sets of same elements happen to add two entries in Dict? I guess I got this condition earlier and changed my code from frozenset(...) to tuple(sorted(frozenset(...))) . Can someone who knows how Dict and frozenset implementation confirm if that is required or not? 回答1: are there cases where two sets of same elements happen to add two entries in Dict? No. frozenset hashing algorithm doesn't depend on the order of the elements, only on elements

Maintaining the order of the elements in a frozen set

戏子无情 提交于 2019-12-05 01:24:21
问题 I have a list of tuples, each tuple of which contains one string and two integers. The list looks like this: x = [('a',1,2), ('b',3,4), ('x',5,6), ('a',2,1)] The list contains thousands of such tuples. Now if I want to get unique combinations, I can do the frozenset on my list as follows: y = set(map(frozenset, x)) This gives me the following result: {frozenset({'a', 2, 1}), frozenset({'x', 5, 6}), frozenset({3, 'b', 4})} I know that set is an unordered data structure and this is normal case

Is it safe to use frozen set as Dict key?

偶尔善良 提交于 2019-12-04 02:37:08
It obviously works but are there cases where two sets of same elements happen to add two entries in Dict? I guess I got this condition earlier and changed my code from frozenset(...) to tuple(sorted(frozenset(...))) . Can someone who knows how Dict and frozenset implementation confirm if that is required or not? georg are there cases where two sets of same elements happen to add two entries in Dict? No. frozenset hashing algorithm doesn't depend on the order of the elements, only on elements themselves. Two FS'es with the same elements are equal and have equal hashes, thus satisfying both