-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiot23_code.py
More file actions
37 lines (24 loc) · 890 Bytes
/
Copy pathiot23_code.py
File metadata and controls
37 lines (24 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import pandas as pd
def load_iot23_data(data_dir):
"""Loads the IoT-23 dataset.
Args:
data_dir: Path to the directory containing the IoT-23 dataset.
Returns:
A pandas DataFrame containing the network traffic data.
"""
data = []
for filename in os.listdir(data_dir):
if filename.endswith(".log.labeled"):
filepath = os.path.join(data_dir, filename)
df = pd.read_csv(filepath, sep=" ")
data.append(df)
return pd.concat(data, ignore_index=True)
# Example usage
data_dir = "/path/to/iot23_dataset"
df = load_iot23_data(data_dir)
# Handle missing values
df = df.fillna(method='ffill') # Forward fill missing values
# Remove duplicate rows
df = df.drop_duplicates()
df['packet_size'] = df['resp_pkts'] * df['resp_bytes'] + df['orig_pkts'] * df['orig_bytes']
df['flow_duration'] = df['duration']