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
0
votes
1 answer

Pandas dataframe OrderedDict extract data

I've a Database.csv file with one column and 3 rows, those are data exported from salesforce with simple-salesforce, I try to get the 'Name' Value from the OrderedDict cell data('Name', 'Demand'). Dataframe Type__c OrderedDict([('attributes',…
Pamuk
  • 3
  • 1
0
votes
2 answers

How to replace existing key in a dictionary in python?

So , I have this code. I want to replace the specific existing key at index 1 in a dictionary in python. Anyone have an idea on this? from collections import OrderedDict regDict= OrderedDict() regDict[("glenn")] = 1 regDict[("elena")] =…
max 2p
  • 27
  • 4
0
votes
2 answers

How to extract second values elements only in every keys in an OrderedDict?

SO, i have this code, i want to extract the second values elements only in every keys in an OrderedDict, i dont want to use for loop,any idea on this ? from collections import OrderedDict regDict= OrderedDict() regDict["glenn"] =…
Glenn Ford
  • 45
  • 7
0
votes
2 answers

How to slice value element in orderedDict in python?

SO,I have this code , how to sliced up value elements in orderedDict? import numpy as np from collections import OrderedDict x = OrderedDict() val= np.array((1,2)) key= 40 x[key]= val x[key]= val,3 print(x) returns : OrderedDict([(40, (array([1,…
Glenn Ford
  • 45
  • 7
0
votes
1 answer

DataFrame to List of OrderedDicts - how to preserve order?

when converting a DataFrame to an OrderedDict with to_dict and into I can't find a way to have it keep the order of the records. Is there a way to do this without looping through the records and converting manually? DataFrame([{"B": 1, "A":…
Michel Müller
  • 4,733
  • 3
  • 23
  • 47
0
votes
1 answer

My Ordered Dict is not working as I expected

So basically I have this code: from collections import OrderedDict as OD person = OD({}) for num in range(10): person[num] = float(input()) tall = max(person.values()) short = min(person.values()) key_tall = max(person.keys()) key_short =…
g_lob00
  • 3
  • 3
0
votes
1 answer

Trying to convert list of OrderedDict to Dictionary Key value Python

I need to convert ordereddict to dictionary key value. test = [OrderedDict([('key', 'value'), ('name', 'A'), ('value', '5')]), OrderedDict([('key', 'value'), ('name', 'B'), ('value',…
KC_1415
  • 25
  • 3
0
votes
1 answer

Tensorflow Error "TypeError: Tensors in list passed to 'values' of 'Pack' Op have types [int32, int64, int32, int32, int32] that don't all match."

I am new to Tensorflow and Keras. I have loaded a dataset from CSV and created a train_dataset as such: column_names = ['a', 'date', 'c', 'd', 'e', 'f'] label_name = column_names[0] feature_names = column_names[1:] class_names = ['good',…
Annabanana
  • 57
  • 2
  • 9
0
votes
1 answer

Python 3 requests POST request data/params issue

The issue is that the data/parameters in the POST request aren't being sent correctly to be processed by the server. I've used Burp to check what's wrong and it seems like the parameters are in the request's body as they should, but the thing is…
Waleed Qutob
  • 45
  • 1
  • 3
  • 7
0
votes
1 answer

Add and change key/value in ordered dictionary without mutating

I am trying to split a value into three different ones with new keys and add them to my dictionary. But I always get the error message: RuntimeError: OrderedDict mutated during iteration def csv_to_dic(file): with open(file, "r") as csvfile: …
0
votes
0 answers

OrderedDict comparison inconsistency

I noticed this striking inconsistency in the relationship between dicts and OrderedDicts. From the docs: Equality tests between OrderedDict objects are order-sensitive and are implemented as list(od1.items())==list(od2.items()). Equality tests…
shx2
  • 53,942
  • 9
  • 107
  • 135
0
votes
1 answer

How to remove a nested entry from Python OrderedDict (ruamel)?

I'm using https://github.com/wwkimball/yamlpath and the excellent ruamel YAML parser to load and work with YAML files. I need to remove an entry from a YAML file but can't see how to obviously do that. Here's an example: Source YAML…
bzo
  • 1,402
  • 6
  • 23
  • 33
0
votes
2 answers

Python, unpack and reorder list of ordered dictionaries

I have a list of ordered dictionaries. I want to set the first value of every dictionary to be the key and the dictionary itself the value (including the name) and return a new list. data = [ OrderedDict( [('Name', 'Tel saki'), ('Area',…
user12177026
0
votes
2 answers

How to access values in ordereddict?

I opened and read csv file from argv to dictionary data = open(argv[1]) reader = csv.DictReader(data) dict_list = [] for line in reader: dict_list.append(line) and now when I want to access the content of the csv file like this: for x in…
Tat
  • 1
  • 1
0
votes
1 answer

Why can we create attributes to the object of an OrderedDict but not for Dict?

When reading some code I found that one can create new attributes for an object of an OrderedDict but when I tried creating one for Python's Dict, Python didn't allow me to. Just wondering why this happened and why it is so that one would want to…