Series数据的sort内置和外置
sort_values函数则是对values进行排序输出,默认inplace参数为假即返回排序后的series,不影响原series。import pandas as pd
idx ="hello the cruel world".split()
val =
t = pd.Series(val, index = idx)
print (t, "<- t")
print (t.sort_values(), "<- t.sort_values()")
print (t, "<- t")
如果想影响原series可以启用函数的inplace参数为True。
import pandas as pd
idx ="hello the cruel world".split()
val =
t = pd.Series(val, index = idx)
print (t, "<- t")
t.sort_index(inplace = True)
print (t, "<- after t.sort_index(inplace=True)")
t.sort_values(inplace = True)
print (t, "<- after t.sort_values(inplace=True)")
程序的执行结果:
hello 1000
the 201
cruel NaN
world 104
dtype: float64 <- t
cruel NaN
hello 1000
the 201
world 104
dtype: float64 <- after t.sort_index(inplace=True)
world 104
the 201
hello 1000
cruel NaN
dtype: float64 <- after t.sort_values(inplace=True)
页:
[1]