Questions tagged [ordereddict]

Python OrderedDict datatype, which remembers the order entries were added to the dictionary.

Python OrderedDict datatype, which remembers the order entries were added to the dictionary. Also see collections — High-performance container datatypes in the Python manual.

77 questions
1
vote
0 answers

Red Black Tree based Dict in Python

I'm trying to use python build a Curve class. In my design, the underlying set of points is better to be implemented in an ordered dict, just like what I have done in C++ with (ordered) map based on the red black tree (RBT). The benefits are a lot,…
Yang Wang
  • 145
  • 5
1
vote
1 answer

Pytorch: how to change requires_grad to be true in an OrderedDict

Suppose I have a neural network object from torch.nn, by default the requires_grad is False for its parameters. I want to change it to be True. But the following naive approach fails: From torch import nn a = nn.Linear(1,…
1
vote
3 answers

How to add N OrderDict() in python

Assuming that I have 2 OrderedDict(), I can get the result of the (+) operation by doing the following action: dict1 = OrderedDict([(52, 0), (53, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0), …
azal
  • 1,055
  • 2
  • 17
  • 35
1
vote
2 answers

How to convert a list of OrderedDict to nested json with grouped keys in python

I'm working on a project where I need to convert a set of data rows from database into list of OrderedDict for other purpose and use this list of OrderedDict to convert into a nested JSON format in python. I'm starting to learn python. I was able…
1
vote
0 answers

How to iterate through an OrderedDict contained in another object generated by Zeep?

I've used Zeep to call a SOAP API and return an object whose ._dict_ attributes list looks like this: {'__values__': OrderedDict([('Ids', { 'Id': [ { 'Name': 'ID Name One', 'Value': '00192' }, { …
1
vote
1 answer

Pandas DataFrame constructor sorts rows, even with OrderedDict as input

I create an OrderedDict: from collections import OrderedDict od = OrderedDict([((2, 9), 0.5218), ((2, 0), 0.3647), ((3, 15), 0.3640), ((3, 8), 0.3323), ((2, 28), 0.3310), ((2, 15), 0.3281), ((2, 10), 0.2938), ((3, 9), 0.2719)]) Then…
Jim
  • 581
  • 4
  • 9
1
vote
1 answer

Wrong order when setting xticks in matplotlib barplot

I'm trying to plot an OrderedDict using matplotlib. The dictionary d is sorted by value, in descending order: OrderedDict([(1, 792), (2, 199), (3, 18), (4, 8), (8, 3), (5, 2), (10, 2), (6, 1), (9, 1)]) This is the code I'm using to draw the…
andy
  • 249
  • 1
  • 10
  • 21
1
vote
2 answers

Why do keys added to an OrderedDict and sorted inside of a function not stay sorted outside the function?

I have a function that contains code similar to the one below, which takes an OrdredDict object and a string as arguments: def AddToOrderedDict(ordered_dict, new_key): ordered_dict[new_key] = [] ordered_dict =…
burritab
  • 23
  • 4
1
vote
2 answers

Python How to convert collections.OrderedDict to dataFrame

I have the following task: 1) I have an excel file with a few spreadsheets. From these spreadsheets I need information from columns "A:CU", rows 41 - 51 2) Then I need to collect information from from columns "A:CU", rows 41 - 51 from all…
kskirpic
  • 87
  • 1
  • 5
1
vote
2 answers

How can I get data with order in python dictionary?

I want to get my keys in my order. But, it doesn't work with dictionary and Collections.OrderedDict. from collections import OrderedDict data = OrderedDict({ "Name1": "value1", "Name2": "value2" }) for key in data.keys(): print(key) This…
Harine
  • 99
  • 1
  • 9
1
vote
1 answer

group values of (ordered) dictionary based on condition within values

I have a sorted dictionary (orderedDict to be exact) and I want to make a new dictionary (or edit the old one) that group specific values based on a condition. The main problem is that I need to check each key in the dictionary with the previous…
Fini
  • 153
  • 7
1
vote
2 answers

OrderedDict skips entries with NaN values

why does OrderedDict and a normal dict behave differently? When I put two entries with NaNs in my dictionary the OrderedDict just skips them and does not recognize them. I tried to put the entries in different order, also trying "NaN" but nothing…
Tim B.
  • 23
  • 3
1
vote
2 answers

Using Python to Create Complex JSON with the Creation of Some Nested Arrays being Conditional

In using Python to dynamically create part of a larger JSON string, I want to add an object (nested dictionary containing list and dictionaries or eventually objects and arrays when converted to JSON) only when the higher level value (in my case…
kilshaw
  • 21
  • 4
1
vote
1 answer

I have a dataframe with shape (601, 2522). I want the indexing to start from the second row of the dataframe

Change the indexing to start from the second row of the dataframe. Because, this dataframe will be transformed into an Ordereddict, where I will use the first row of the element as labels for my dataset. -Tried multiindexing in the dataframe, but…
1
vote
1 answer

How to format JSON item OrderedDic dumps with substrings-PYTHON 3

I am trying to convert a Json file that looks like { # "item_1":"value_11", # "item_2":"value_12", # "item_3":"value_13", # "item_4":["sub_value_14", "sub_value_15"], # "item_5":{ # "sub_item_1":"sub_item_value_11", # …
Coder123
  • 236
  • 1
  • 13