Python演示如何从数据帧打印前10个最大值和最小值

Python演示如何从数据帧打印前10个最大值和最小值,python,pandas,Python,Pandas,我如何才能只获得价值最高的10个项目?还有价值最低的10项? 我试过了。max()它只返回值 存储在coeff_参数变量中的数据 我试过了 coeff_parameter.sort_values 但它不起作用 coeff_parameter = pd.DataFrame(model.coef_,X.columns,columns=['Coefficient'].sort_values().head()) AttributeError:“list”对象没有属性“sort\u values”c

我如何才能只获得价值最高的10个项目?还有价值最低的10项? 我试过了。max()它只返回值

存储在coeff_参数变量中的数据 我试过了

coeff_parameter.sort_values
但它不起作用

coeff_parameter = pd.DataFrame(model.coef_,X.columns,columns=['Coefficient'].sort_values().head())

AttributeError:“list”对象没有属性“sort\u values”

coeff\u参数。nsmallest(n=10)


coeff\u parameter.nlargest(n=10)

你真的应该利用搜索引擎,看看熊猫的文档。谷歌
pandas sort\u value
pandas nlargest
将引导您找到正确的位置

看看,
sort_values
作用于数据帧对象,而不是列表对象。它在method参数中按defalut以
singressing=True
进行升序排序,这意味着较低的值具有较小的索引

coeff_parameter=pd.DataFrame(model.coef_,X.columns,columns=['Coefficient'])
已经返回了DataFrame对象。您所需要做的就是对这个
coeff\u参数
dataframe对象执行操作

获取
coeff_参数
系数
的最大/最小值。您可以先对该列排序,然后从中获取第一个第n行,或者只使用or

coeff_参数.nlagest(10)
coeff_参数nsmallest(10)
coeff_参数.排序_值(['Coefficient']).head()
coeff_参数.排序_值(['Coefficient']).tail()

nlargest/nsmallest
@QuangHoang我应该在哪里键入nlargest/nsmallest?包括您的代码并描述存储数据的结构。对于列表,排序(),然后取前10项,如my_list[:10],最后10项,如my_list[-10:]。
sort_values()
head()/tail()@Ynjxsjmh coeff_参数。sort_values()head()?
coeff_parameter = pd.DataFrame(model.coef_,X.columns,columns=['Coefficient'].sort_values().head())