'ascending=False is not working panda dataframe

Accending False unable to give me most data from biggest number.

import pandas as pd
from binance.client import Client

client = Client()
ticker_info = pd.DataFrame(client.get_ticker())
busd_info = ticker_info[ticker_info.symbol.str.contains('USDT')]
busd_info = busd_info.sort_values(by='priceChangePercent', ascending=False)
# busd_info = busd_info.priceChangePercent.max()
print(busd_info.head(60))
print(busd_info)

enter image description here



Solution 1:[1]

If test dtype:

print (busd_info.priceChangePercent.dtype)
object

It means there are not numeric values so sorted like strings in lexicographical order.

For convert to numeric use to_numeric with errors='coerce' for convert if exist not numeric value to NaNs:

busd_info.priceChangePercent = pd.to_numeric(bush_info.priceChangePercent, errors='coerce')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jezrael