Bilentor

5

votes
0

answer
35

views

Template metafunctions to generate pybind11 bindings

I am trying to create python bindings for some C++ functions using pybind11. The functions are templated but in the python bindings, I need one of the template parameter to be a function argument. Currently the way I have it is a lot of repetition for each template parameter. enum MyEnum {E1, E2, E3...
Bilentor
4

votes
3

answer
1.9k

views

Transposing (pivoting) a dict of lists in python [duplicate]

This question already has an answer here: list of dicts to/from dict of lists 10 answers I have a dictionary that looks like: {'x': [1, 2, 3], 'y': [4, 5, 6]} I want to transform it to the following format: [{'x': 1, 'y': 4}, {'x': 2, 'y': 5}, {'x': 3, 'y': 6}] I can do it by explicit loops but is...
Bilentor
2

votes
1

answer
266

views

Python: Replace keys in a nested dictionary

I have a nested dictionary {1: {2: {3: None}}} and a dictionary that maps keys of the nested dictionary to a set of values such as {1: x, 2: y, 3: z}. I want to transform the nested dictionary to this form {x: {y: {z: None}}}. I have tried a couple of recursive functions but I keep going in circles...
Bilentor
2

votes
3

answer
147

views

Subtracting subcolumn from a column of a dataframe

I have a dataframe as follows: name tag price 0 x1 tweak1 1.1 1 x1 tweak2 1.2 2 x1 base 1.0 3 x2 tweak1 2.1 4 x2 tweak2 2.2 5 x2 base 2.0 I want to subtract the base price from price column and create a new column as follows: name tag...
Bilentor