Created
March 19, 2023 01:27
通信情報集約
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ファイルを分割せずに、集約して出力する | |
#PC間の通信回数を抽出 | |
device_weight = [] | |
from_device = [] | |
to_device = [] | |
from_packets = [] | |
to_packets = [] | |
from_bytes = [] | |
to_bytes = [] | |
duration = [] | |
start = time.time() | |
index = 1 | |
for src, sub_df in df.groupby('SrcDevice'): | |
for dst, subsub_df in sub_df.groupby('DstDevice'): | |
from_device.append(src) | |
to_device.append(dst) | |
cnt = len(subsub_df) | |
device_weight.append(cnt) | |
from_packets.append(subsub_df['SrcPackets'].sum()) | |
to_packets.append(subsub_df['DstPackets'].sum()) | |
from_bytes.append(subsub_df['SrcBytes'].sum()) | |
to_bytes.append(subsub_df['DstBytes'].sum()) | |
duration.append(subsub_df['Duration'].sum()) | |
print('{0} %完了'.format(index / len(SrcDevice_list) * 100)) | |
index += 1 | |
# if index > 30: | |
# break | |
df_sum = pd.DataFrame({'from': from_device, 'to': to_device, 'count' : device_weight, 'duration': duration, 'from_packets': from_packets, 'to_packets': to_packets, 'from_bytes': from_bytes, 'to_bytes': to_bytes}) | |
df_sum.to_csv('netflow_day-02_sum.csv') | |
elapsed_time = time.time() - start | |
print ("calclation_time:{0}".format(elapsed_time) + "[sec]") | |
df_sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment