gpt4 book ai didi

python - 从表中删除行,但根据项目数创建行的索引

转载 作者:行者123 更新时间:2023-12-04 12:09:04 25 4
gpt4 key购买 nike

我为表格制作了一个脚本,但有时表格制作者会插入一些不是值的东西。我想做一些自动的事情,而不必进入表格并删除那些行。我设法删除了这些行,但行的索引仍然存在,我需要行的索引正确(0、1、2、3、4、5、6 ...)
例如,在我当前使用的表中,必须删除索引为 0 的行,当我创建新表时,表的索引以 1 开头

for i in range(table.shape[0]):
if pd.isna(table[1][i]) == True:
table = table.drop(labels=i, axis=0)

table2 = pd.DataFrame(table)

最佳答案

根据基思约翰逊的回答,我研究并设法找到了解决方案

table2.reset_index(inplace=True, drop=True)

关于python - 从表中删除行,但根据项目数创建行的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68400406/

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