马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
sort_values函数则是对values进行排序输出,默认inplace参数为假即返回排序后的series,不影响原series。import pandas as pd
idx = "hello the cruel world".split()
val = [1000, 201, None, 104]
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 = [1000, 201, None, 104]
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) |