本文介绍了pandas sort_values函数中axis = 1的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码段.
df = pd.DataFrame({'col1' : ['A', 'A', 'B', np.nan, 'D', 'C'],
'col2' : [2, 1, 9, 8, 7, 4],
'col3': [0, 1, 9, 4, 2, 3]})
print(df)
sorted=df.sort_values(by=1,axis=1)
print(sorted)
以上数据为原始数据框.
The above data is original dataframe .
上面的是df.sort_values()函数的输出.
The above one is output of the df.sort_values() function.
任何人都可以解释这里发生了什么吗?
Can anyone explain what is happening here?
推荐答案
参数axis=1
表示列,而0表示行.在这种情况下,您将按列排序,特别是索引1,即col2
(Python中的索引从0开始).
The parameter axis=1
refer to columns, while 0 refers to rows. In this case you are sorting by columns, specifically index 1, which is col2
(indexing in python starts at 0).
这里有一些很好的例子: https://pandas.pydata.org/pandas-docs/stable/generation/pandas.DataFrame.sort_values.html
Some good examples here: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort_values.html
这篇关于pandas sort_values函数中axis = 1的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!