2024-09-19 20:59:18 发布
网友
所以我需要这段代码来不断删除行,直到A1单元格是一个特定的字符串,我尝试了以下方法:
while table[0][0] != 'Nº TAD': table = table.drop(table.index[0])
但似乎循环的次数比我想要的要多,我不知道为什么
这正是你想要的。只需将if检查与要检查的string交换即可df是你的{}
string
df
In[16]: df Out[16]: 0 1 2 3 0 1 2 3 4 1 1 2 3 4 2 1 2 3 4 3 5 6 7 8 In[17]: new_df = df ...: for num, row in enumerate(df.values): ...: if row[0] == 5: ...: break ...: else: ...: new_df = new_df.drop(num) ...: In[18]: new_df Out[18]: 0 1 2 3 3 5 6 7 8
您可以按如下方式创建行:
for index, row in table.iterrows(): if row["col_name"] == 'Nº TAD': break table.drop([index],inplace=True)
这正是你想要的。只需将if检查与要检查的}
string
交换即可df
是你的{您可以按如下方式创建行:
相关问题 更多 >
编程相关推荐