Coolio2654
Coolio2654

Reputation: 1739

Error slicing list of dictionaries by key?

I have a Pandas Series which contains dictionaries holding two key-value pairs each.

Here is a picture of the data (apologies for size)

enter image description here

How would I go about getting all of the 'C' key's values, like [10000000.0, 3162277.66 ..., 1000000.0, ...] here? I've already tried sorted_combos.iloc[:, 0]['C'], but that gives me a KeyError, so I am stumped.

How am I do to this for future reference? Thank you all in advance.

Upvotes: 1

Views: 57

Answers (1)

Mike Chen
Mike Chen

Reputation: 89

You can try using a list comprehension to loop over all the dictionaries. In this case, the code would be [dic['C'] for dic in sorted_combos.iloc[:,0]].

Upvotes: 1

Related Questions