gpt4 book ai didi

python - 通过取模删除行来缩小 pandas Df

转载 作者:太空宇宙 更新时间:2023-11-03 16:11:13 25 4
gpt4 key购买 nike

我需要减少(或选择)例如索引 4 的倍数。我有一个 2MS 数据框,我想为 future 的绘图获取更少的数据。所以我们的想法是使用 1/4 的数据。只留下索引为 4 - 8 - 16 - 20 - 4*n 的行(或者可能相同但索引为 5*n)如果有人有任何想法,我将不胜感激。

最佳答案

您可以使用iloc 函数,该函数采用行/列切片。

来自docs

Purely integer-location based indexing for selection by position.

.iloc[] is primarily integer position based (from 0 to length-1 of the axis), but may also be used with a boolean array.

所以你可以写df.iloc[::4, :]

关于python - 通过取模删除行来缩小 pandas Df,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39294132/

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