Skip to content
Advertisement

Sort a dict of DataFrames

I have a dict of data-frames like the following:

symbols ={BTC: DF, ETH: DF, DOGE:df}

where each DF looks like this.

JavaScript

I am trying to sort the dict by the price_change in the last row.

Advertisement

Answer

You could figure out the sorting of the keys by using a lambda function on sorted, which gets the last price change per df. Using reverse=True would sort them in the order I believe you are looking for. Then it’s a matter of reconstructing a new dict in that order using dict comprehension.

JavaScript

Output

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement