题目
如何对df中列名为“age”的数据进行升序 排序 A. df. sort('age', ascending=True)B. df. sort ____ values('age', ascending=True)C. df. sort ____ by('age', ascending=True)D:df. order('age', ascending=True)
如何对df中列名为“age”的数据进行升序 排序
- A. df. sort('age', ascending=True)
- B. df. sort ____ values('age', ascending=True)
- C. df. sort ____ by('age', ascending=True)D:df. order('age', ascending=True)
题目解答
答案
B
解析
步骤 1:理解问题
问题要求对DataFrame对象df中名为“age”的列进行升序排序。在pandas中,有几种方法可以实现这一目标,但需要选择正确的函数和参数。
步骤 2:分析选项
A. df.sort('age', ascending=True):这是早期版本pandas中使用的函数,但现在已经弃用。
B. df.sort_values('age', ascending=True):这是当前版本pandas中推荐使用的函数,用于根据列值排序。
C. df.sort_by('age', ascending=True):这不是pandas中的函数。
D. df.order('age', ascending=True):这是早期版本pandas中使用的函数,但现在已经弃用。
步骤 3:选择正确答案
根据pandas的最新文档,正确的方法是使用df.sort_values()函数,因此选项B是正确的。
问题要求对DataFrame对象df中名为“age”的列进行升序排序。在pandas中,有几种方法可以实现这一目标,但需要选择正确的函数和参数。
步骤 2:分析选项
A. df.sort('age', ascending=True):这是早期版本pandas中使用的函数,但现在已经弃用。
B. df.sort_values('age', ascending=True):这是当前版本pandas中推荐使用的函数,用于根据列值排序。
C. df.sort_by('age', ascending=True):这不是pandas中的函数。
D. df.order('age', ascending=True):这是早期版本pandas中使用的函数,但现在已经弃用。
步骤 3:选择正确答案
根据pandas的最新文档,正确的方法是使用df.sort_values()函数,因此选项B是正确的。