我希望能够从DataFrame中取出一行数据,并将其添加到DataFrame的开头或结尾。
下面是我的代码,它可以实现这个功能,但我不确定是否使用了正确的方法,或者是否有更简单、更好、更快的方法?
下面是我的代码,它可以实现这个功能,但我不确定是否使用了正确的方法,或者是否有更简单、更好、更快的方法?
testdf = df.copy()
#get row
target_row = testdf.ix[[2],:]
#del row from df
testdf.drop([testdf.index[2]], axis=0, inplace=True)
#concat original row to end or start of df
newdf = pd.concat([testdf, target_row], axis=0)
谢谢
a
中的4
消失了。这是期望的输出吗? - AsheKetchum.ix
已被弃用,请使用.iloc
代替。 - raummensch