gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 02:43:55 26 4
gpt4 key购买 nike

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

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

关于Python DataFrame 未保存。如何永久分配呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45399395/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com