gpt4 book ai didi

python - 关于 Python Pandas,删除该行

转载 作者:太空宇宙 更新时间:2023-11-03 23:54:24 24 4
gpt4 key购买 nike

<分区>

全部。

我创建了导入 excel 文件的 Python 代码,如果它符合条件,则使用“while”和“if”状态删除原始文件。比较完成后,将结果导出一个excel文件。没有错误编码,但删除原始文件不起作用,因为当我打开结果 excel 文件时,它与导入的 excel 文件完全相同。我认为“data.drop(data.index[pointer+a])”不起作用。你能帮帮我吗?

import pandas as pd

data = pd.read_excel('20190924_1147-50_result.xlsx', index_col = 0)
print('\nExcel file reading complete')
a = 1
pointer = 0
del_indicator = 0

data = data.drop_duplicates(['Src IP', 'Dst IP', 'Dst Port'], keep='first')
print('SrcIP, DstIP, Dst Port are Deduplicated\n')

while True:
if pointer == 2906 :
print(pointer, data.iloc[pointer, 3])
break
elif pointer+a == 2906 :
pointer +=1
a = 1
elif data.iloc[pointer, 2] == data.iloc[pointer+a, 3] and data.iloc[pointer, 3] == data.iloc[pointer+a, 2] and data.iloc[pointer, 6] == data.iloc[pointer+a, 5]:
print('\n-----', data.iloc[pointer, 0], data.iloc[pointer, 2], data.iloc[pointer, 3])
print('-----', data.iloc[pointer+a, 0], data.iloc[pointer+a, 2], data.iloc[pointer+a, 3])

data.drop(data.index[pointer+a])

a+=1
else:
a+=1

print('Deleting session traffic Finished')

data.to_excel('20190924_1147-50_result_test.xlsx', sheet_name = 'Using data')
print('Finished creating result excel file')

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