Questions tagged [frozenset]

questions related to frozenset objects in Python

frozenset is a built-in type for Python programming language. The elements of a set must be hashable. To represent sets of sets, the inner sets must be frozenset objects.

A set is a collection in which no element is repeated. It is often implemented by hashing the objects as they are added to the set, and comparing against those hashes for operations on the set.

See also

Read more here

85 questions
2
votes
0 answers

Need to do further operations on an immutable frozen set in a pandas dataframe

I am trying to do a join on two pandas dataframes, one of which is the result of running an Apriori algorithm from the mlxtend package. When I tried joining the two, it outputted a bunch of None's. I think that at least one of the reasons for this…
bernando_vialli
  • 947
  • 4
  • 12
  • 27
2
votes
1 answer

Writing elements of a frozen set to a pandas dataframe

I have a frozen set whose elements are like this: {frozenset({'e', 'f'}), frozenset({'a', 'b'}), frozenset({'c', 'd'}),....} I want to write the elements in the frozen set to a pandas dataframe like this: col1 col2 0 a b 1 c d 2 e …
enterML
  • 2,110
  • 4
  • 26
  • 38
2
votes
3 answers

python delete list from another list

There're two lists like [[A, A], [B, B], [C, C], [D, D]] and [[A, A], [B, B]] How to delete list 2 from 1 with result [[C, C], [D, D]] and make it without loop, because both lists are very big and loops works slow? thanks list examples >>>a =…
2
votes
2 answers

Python 2.7 on OS X: TypeError: 'frozenset' object is not callable on each command

I have this error on each my command with Python: ➜ /tmp sudo easy_install pip Traceback (most recent call last): File "/usr/bin/easy_install-2.7", line 11, in load_entry_point('setuptools==1.1.6', 'console_scripts', 'easy_install')() …
andre487
  • 1,261
  • 2
  • 18
  • 27
2
votes
0 answers

Python frozenset writing to JSON

I have a dictionary with frozenset-typed (variable-length, non-duplicate data) keys and I need to write this dictionary into a JSON file. However, my problem is that frozenset (although immutable) is not a Python simple data type and I get this type…
2
votes
1 answer

Python set intersections, any way to return elements from the larger set?

When Python takes the intersection of two sets, it always returns elements from the smaller one, which is reasonable in nearly all cases, but I'm trying to do the opposite. In the piece of code below, note that the intersection yields an integer,…
Steve Zelaznik
  • 616
  • 7
  • 16
2
votes
1 answer

Should instances of a frozenset subclass be hashable in Python 3?

According to https://docs.python.org/2/library/stdtypes.html#frozenset, in Python 2: The frozenset type is immutable and hashable -- its contents cannot be altered after is created; however, it can be used as a dictionary key or as an element of…
pzrq
  • 1,626
  • 1
  • 18
  • 24
2
votes
1 answer

python TypeError: frozenset expected at most 1 arguments, got 4

I'm getting this error when trying to make a frozen set: class Transcriber: DNA_BASES = frozenset('A','T','G','C') ... And this is the Traceback: ~/python/project5$ python wp_proj5.py Traceback (most recent call last): File "wp_proj5.py",…
Tom
  • 9,275
  • 25
  • 89
  • 147
1
vote
1 answer

Improve print readability of nested Frozenset

The output of the code example below has terrible readability. The data I'd like to analyse is hidden within numerous frozenset({}) prints. A = frozenset(["A1", "A2"]) B = frozenset(["B1", "B2"]) C = frozenset(["C1", "C2"]) foo = {A, B,…
Victor
  • 35
  • 7
1
vote
1 answer

When I inherit from frozenset, I get TypeError: object.__init__() takes exactly one argument (the instance to initialize)

I want to inherit from frozenset and change the constructor. What I actually want to do is to make a singleton fronzeset, but instead here I'll provide a simplified example: class B(frozenset): def __init__(self): super().__init__([1, 2,…
CrabMan
  • 1,578
  • 18
  • 37
1
vote
1 answer

filter dataframe of frozensets if they have a certain elemnet

I would like to filter a datframe that has association rules results. I want antecedents that contain an element like H or L in my case. The antecedents are frozenset types. I tried Hrules but it is not working. Hrules=fdem_rules['H' in…
Saif
  • 95
  • 8
1
vote
1 answer

TypeError: unhashable type: 'set' in dropdown plotly python

The following code works by itself but I have a "TypeError: unhashable type: 'set'" when it's in my plotly graph. Can you help me out with this ? I never worked with set or frozenset. Thanks a lot ! code that works be itself : updatemenus = [] for…
mfou
  • 11
  • 2
1
vote
1 answer

How to extract the value from a frozen set that was converted to a string with python?

I am working on a python map/reduce in multiple parts. My first map prints to the stdin so that the first reduce can pick it up. The result of the map looks like this: frozenset([4]) 14 The reduce reads in frozenset([4]) as the key, and 14 as the…
1
vote
0 answers

How is equality determined for Python frozenset instances?

How is the code below possible? >>> frozenset(('a_')) == frozenset(['a_']) False >>> frozenset(('a')) == frozenset(['a']) True My understanding is that so long as each each element of the iterable is hashable, a frozen set will be instantiated with…
Greg
  • 193
  • 1
  • 1
  • 11
1
vote
2 answers

Frozenset union of two columns

I have a dataset containing two columns with frozensets. Now I would like to merge/take the union of these frozensets. I can do this with a for loop, however my dataset contains > 27 million rows, so I am looking for a way to avoid the for loop.…
Tox
  • 834
  • 2
  • 12
  • 33