Python Forum
When dictionarys do no have same keys
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
When dictionarys do no have same keys
#1
I am new to accessing nested dictionaries and here is the problem I have. One of my columns in a panda frame contains dictionaries. These dictionaries have as a first key ta number, that is not sequential.

To simplify the problem I print just the first entry of the panda frame column.
print(df.report[0])
Quote:{'253.0': {'precision': 0.8333333333333334, 'recall': 0.375, 'f1-score': 0.5172413793103448, 'support': 80}, '305.0': {'precision': 0.8132780082987552, 'recall': 0.9655172413793104, 'f1-score': 0.882882882882883, 'support': 203}, '308.0': {'precision': 0.9594594594594594, 'recall': 0.9861111111111112, 'f1-score': 0.9726027397260274, 'support': 216}, 'accuracy': 0.8797595190380761, 'macro avg': {'precision': 0.8686902670305159, 'recall': 0.7755427841634739, 'f1-score': 0.7909090006397518, 'support': 499}, 'weighted avg': {'precision': 0.8797702316524192, 'recall': 0.8797595190380761, 'f1-score': 0.8630996540097691, 'support': 499}}

In that dictionary the keys are:

253 305.0 308.0

I would like to use those keys to select the next available nested-dictionary to access the precision values.

I highlighted with bold the keys and the precision value I would like to get. If this makes it easier I would be still happy with just the precision values returned as a list. Where I am stuck is that in python I get do something like get to pick keys but my keys are not fixed.

Can you help me with that?

Regards Alex
Reply


Messages In This Thread
When dictionarys do no have same keys - by dervast - Dec-05-2019, 10:04 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020