Skip to content
Advertisement

Tag: dictionary

Dictionary of np arrays

I am working on a load function that loads files containing one pandas dataframe per file (or even better one np array). I.e. I am loading a .csv file and I want to link it to only one array variable. This function takes as input one dictionary containing the name I want (as key) the variable to take and the

How to calculate percentages inside nested dictionaries in Python

I have two dictionaries: For every key in the People dictionary, I want to calculate the percentage of values(fruits count) based on the fruit dictionary broken down by individual fruits and all fruits combined. This is how the calculation is: {‘sam’:{‘mango’:3/12 = 0.25,’kiwi’:12/24 = 0.5, ‘total’: (3+12)/(12+24) = 0.41} Finally, my output should look like this: Can anyone help me

Iterate through dict with keys being strings with index

I have a dictionary in the following form: I need to get 4 lists of the following form: I am trying to find a way to do it by including the key, for example to have an index form 1 to 2 and do string matching with “Pbat_ch[“+str(index)+”]”. Any better idea of how to achieve that? Answer As your “indices”

Advertisement