python - 如何在没有列名的情况下使用 Pandas 进行排序

标签 python sorting pandas

我的数据是:

import pandas
A=pandas.read_csv(r'D:\AUL_prediction\Merge_file\plasmid',sep='   ',header=None, engine='python')
print A

结果是:

                 0     1                 2            3  
                 0     plasmid.gb        NC021289.1    75   
                 1     plasmid.gb        NC016815.1   763   
                 2     plasmid.gb      NZCP011480.1   102   
                 3     plasmid.gb        NC017324.1  1278   
                 4     plasmid.gb        NC007488.2    32   
                 5     plasmid.gb        NC019848.2   632   
                 6     plasmid.gb      NZCP007644.1   208   
                 7     plasmid.gb        NC007336.1    46   
                 8     plasmid.gb      NZCP012748.1   402   
                 9     plasmid.gb      NZCP011248.1   353   

我想根据 A[3] 和 A[2] 对这些数据进行排序,有人知道怎么做吗?我尝试了 sort_values,但是,它无法识别列名“0”或“1”

最佳答案

这个问题很老,但我刚遇到这个问题!

当您没有列标题时,只需提供值并避免在 df.sort_values 中使用关键字 by。解决方案:

df = df.sort_values(df.columns[i])

在你的例子中 df 是 Ai 是列的索引。

关于python - 如何在没有列名的情况下使用 Pandas 进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43292729/

相关文章:

c++ - 在C++中按字母顺序将节点添加到链表

python - pandas TimeGrouper 自定义频率时间范围

带有嵌套列表的 Python 字典键到 pandas DataFrame

python - 以行为条件选择 DataFrame 中的列

python - 属性错误 : 'SMOTE' object has no attribute '_validate_data'

python - setuptools、easy_install 和自定义 pypi 服务器

python - "Order By" Elasticsearch

python - 使用常量初始化时,Tensorflow 使用过多内存

c++ - 我们可以将数组变量添加到整数吗?

python - 根据python pandas中的行值合并两个数据框