Python 为什么按小数字排序不起作用?
看起来熊猫排序不再起作用了:Python 为什么按小数字排序不起作用?,python,pandas,Python,Pandas,看起来熊猫排序不再起作用了: import pandas as pd from numpy import random sample = random.uniform(low=0.0, high=1.0, size=(100,)) ranking = pd.DataFrame(sample, columns=['random']).sort_values(by='random', ascending='False') print(ranking.head()) random 18
import pandas as pd
from numpy import random
sample = random.uniform(low=0.0, high=1.0, size=(100,))
ranking = pd.DataFrame(sample, columns=['random']).sort_values(by='random', ascending='False')
print(ranking.head())
random
18 0.024665
71 0.028709
51 0.037635
48 0.038073
57 0.072323
相反,我希望是相反的顺序,因为升序=False
我使用的是pandas 0.25.0。问题是,如果
'False'
不是布尔值,但字符串的计算方式与True
类似,那么请删除'
:
字符串
'False'
不是布尔值False
ascending=“False”
将被解释为ascending=True
,因为我是盲人。周五早上,在Java和python之间的切换让我丧命。@Erfan否决票适用于这个问题,而不是用户。这个问题在我看来很糟糕,因为它是由于用户代码中的输入错误造成的,不太可能对其他用户有用,因为这个错误与熊猫或排序无关(我99.9%确定这是重复的)。所以,如果这个问题出现在评论队列中,我可能会建议对它进行否决投票。@Erfan,如果你看的话,我是这样做的。不过,这个问题仍然很糟糕。
print(bool('False'))
True
ranking = pd.DataFrame(sample, columns=['random']).sort_values(by='random', ascending=False)
print(ranking.head())
random
44 0.997583
18 0.982477
19 0.979080
16 0.968516
15 0.962161