-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset.py
64 lines (51 loc) · 1.91 KB
/
dataset.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import zipfile
import os
import glob
import pandas as pd
def reboot(filename):
if "after" in filename:
return "After"
elif "before" in filename:
return "Before"
else:
raise KeyError
def merge_csv_files(input_folder, output_file):
# List all CSV files in the input folder
csv_files = glob.glob(os.path.join(input_folder, '*.csv'))
# Initialize an empty DataFrame to store the merged data
all_data = []
# Read each CSV file and append its data to the merged DataFrame
for csv_file in csv_files:
filename = csv_file.split('/')[-1].split('_')
data = pd.read_csv(csv_file)
data['Reboot'] = reboot(filename)
all_data.append(data)
# Concatenate all DataFrames in the list into one DataFrame
merged_data = pd.concat(all_data)
# Write the merged data to a single CSV file
merged_data.to_csv(output_file, index=False)
print(f'Merged data saved to {output_file}')
def extract_zip(archivo_zip):
# Extract the zip file
with zipfile.ZipFile(archivo_zip, 'r') as zip_ref:
# Extract all contents
zip_ref.extractall()
# List all the .csv files in the
input_folder = zip_ref.namelist()[0]
csv_files = sorted([name for name in zip_ref.namelist() if '.csv' in name])
print("The following files were extracted:\n")
for file in csv_files:
# Print the name of the csv files
filename = file.split('/', 1)[1]
print("\t*", filename)
# Output file path for the merged CSV
output_file = 'full-dataset-CCCS-CIC-AndMal-2020.csv'
# Call the function to merge CSV files
merge_csv_files(input_folder, output_file)
def main():
# Name of .zip file
archivo_zip = 'AndMal2020-Dynamic-BeforeAndAfterReboot.zip'
# extrar
extract_zip(archivo_zip)
if __name__ == "__main__":
main()