查找列中的唯一值,然后对它们进行排序 [英] Find the unique values in a column and then sort them
本文介绍了查找列中的唯一值,然后对它们进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个熊猫数据框.我想按升序打印其中一列的唯一值.这就是我的做法:
I have a pandas dataframe. I want to print the unique values of one of its columns in ascending order. This is how I am doing it:
import pandas as pd
df = pd.DataFrame({'A':[1,1,3,2,6,2,8]})
a = df['A'].unique()
print a.sort()
问题是我得到了一个 None
输出.
The problem is that I am getting a None
for the output.
推荐答案
sorted(iterable)
:从 iterable 中的项目返回一个新的排序列表.
代码
sorted(iterable)
: Return a new sorted list from the items in iterable.
CODE
import pandas as pd
df = pd.DataFrame({'A':[1,1,3,2,6,2,8]})
a = df['A'].unique()
print(sorted(a))
输出
[1, 2, 3, 6, 8]
这篇关于查找列中的唯一值,然后对它们进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文