Я пытаюсь агрегировать данные в кадре данных по определенным столбцам.Когда я использую конструктор данных, он работает:
df = pd.DataFrame([
["Firewall-1","outside","tcp","4.4.4.4",53,"1.1.1.1",1025,"outbound","allowed","",2],
["Firewall-1","outside","tcp","4.4.4.4",53,"1.1.1.1",1026,"outbound","allowed","",2],
["Firewall-1","outside","tcp","4.4.4.4",22,"1.1.1.1",1028,"outbound","allowed","",2],
["Firewall-1","outside","tcp","3.3.3.3",22,"2.2.2.2",2200,"outbound", "allowed","",2]
],
columns=["dvc","src_interface","transport","src_ip","src_port","dest_ip","dest_port","direction", "action", "cause", "count"])
index_cols = df.columns.tolist()
index_cols.remove("dest_port")
df = df.groupby(index_cols)["dest_port"].apply(list)
df = df.reset_index()
DATAFRAME
dvc src_interface transport src_ip src_port dest_ip dest_port direction action cause count
0 Firewall-1 outside tcp 4.4.4.4 53 1.1.1.1 1025 outbound allowed 2
1 Firewall-1 outside tcp 4.4.4.4 53 1.1.1.1 1026 outbound allowed 2
2 Firewall-1 outside tcp 4.4.4.4 22 1.1.1.1 1028 outbound allowed 2
3 Firewall-1 outside tcp 4.4.4.4 22 1.1.1.1 1029 outbound allowed 2
4 Firewall-1 outside tcp 3.3.3.3 22 2.2.2.2 2200 outbound allowed 2
OUTPUT
dvc src_interface transport src_ip src_port dest_ip direction action cause count
Firewall-1 outside tcp 3.3.3.3 22 2.2.2.2 outbound allowed 2 [2200]
4.4.4.4 22 1.1.1.1 outbound allowed 2 [1028, 1029]
53 1.1.1.1 outbound allowed 2 [1025, 1026]
Проблема заключается в том, что я пытаюсь импортировать данные из CSV:
fwdata = pd.concat([pd.read_csv(f) for f in glob.glob('*.csv')], ignore_index = True)
df = pd.DataFrame(fwdata)
index_cols = df.columns.tolist()
index_cols.remove("dest_port")
df = df.groupby(index_cols)["dest_port"].apply(list)
df.reset_index()
print(df.head(10))
DATAFRAME То же, что и выше
OUTPUT
Series([], Name: dest_port, dtype: float64)
Файл CSV содержит те же данные, что и конструктор выше, но, похоже, обрабатывается по-другому.Любая помощь будет оценена.Заранее спасибо!
CSV
dvc,"src_interface",transport,"src_ip","src_port","dest_ip","dest_port",direction,action,cause,count "Firewall-1",outside,tcp,"4.4.4.4",53,"1.1.1.1",1025,outbound,allowed,"",2 "Firewall-1",outside,tcp,"4.4.4.4",53,"1.1.1.1",1026,outbound,allowed,"",2 "Firewall-1",outside,tcp,"4.4.4.4",22,"1.1.1.1",1028,outbound,allowed,"",2 "Firewall-1",outside,tcp,"3.3.3.3",22,"2.2.2.2",2200,outbound,allowed,"",2