ascending=False 不工作熊猫数据框

ascending=False is not working panda dataframe

Acceding False 无法从最大的数字中给我最多的数据。

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)

你能试试看你的数据类型是什么吗?

print(busd_info.dtypes)

如果不是你想要的类型,比如你的priceChangePercent应该是float类型,你可以先转换再排序。

# Convert to correct type
busd_info.priceChangePercent = bush_info.priceChangePercent.astype(float)

# Sorting 
busd_info = busd_info.sort_values(by='priceChangePercent', ascending=False)

print(busd_info)

如果测试dtype:

print (busd_info.priceChangePercent.dtype)
object

这意味着没有像字符串那样按字典顺序排序的数值。

要转换为数字,使用 to_numericerrors='coerce',如果不存在数字值,则转换为 NaNs:

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