gpt4 book ai didi

python - df.reset_index(drop=true) 可以在 Python Pandas 中设置为默认值吗?

转载 作者:行者123 更新时间:2023-12-01 04:58:15 30 4
gpt4 key购买 nike

当在 Python Pandas 中对数据帧进行切片时,它会记住行的索引。如果你不想要这个,你可以使用 df.reset_index(drop=true)。但是有没有办法可以将其设置为默认值?我总是想重置我的索引。

还有什么情况下你想记住索引?

谢谢

最佳答案

您可以通过设置func_defaults来更改默认值:

import pandas as pd
import numpy as np
pd.DataFrame.reset_index.im_func.func_defaults = (None, True, False, 0, '')
df = pd.DataFrame(np.random.randint(0, 10, (10, 4)), columns=list("ABCD"), index=np.ones(10))
df.reset_index()

关于python - df.reset_index(drop=true) 可以在 Python Pandas 中设置为默认值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26874921/

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