Python DataFrame 未保存。如何永久分配它?

Python DataFrame not getting saved. How to permanently assign it?

我通过反转其索引将数据框分配给自己。但是当我再次调用它时,它显示的是旧的数据帧,但没有反转它。

apple = apple.reindex(index = apple.index[::-1])
apple.head()

如有任何帮助,我们将不胜感激。 提前致谢:)

对我来说效果很好。

np.random.seed(45)
apple = pd.DataFrame(np.random.randint(10, size=(3,4)), 
                     columns=list('abcd'), 
                     index=list('ABC'))

print (apple)
   a  b  c  d
A  3  0  5  3
B  4  9  8  1
C  5  9  6  8

apple = apple.reindex(index = apple.index[::-1])
print (apple)
   a  b  c  d
C  5  9  6  8
B  4  9  8  1
A  3  0  5  3

另一个解决方案DataFrame.iloc

apple = apple.iloc[::-1]
print (apple)
   a  b  c  d
C  5  9  6  8
B  4  9  8  1
A  3  0  5  3