-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter_data.py
More file actions
28 lines (21 loc) · 971 Bytes
/
filter_data.py
File metadata and controls
28 lines (21 loc) · 971 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
import os
import pandas as pd
def filter_and_save_data(input_path: str, output_path: str):
# Завантаження даних
df = pd.read_csv(input_path, parse_dates=["timestamp"])
# Фільтрація
df.dropna(inplace=True) # видаляє рядки з NaN
df.drop_duplicates(inplace=True) # видаляє дублікати
df.sort_values("timestamp", inplace=True) # сортує по часу
df.reset_index(drop=True, inplace=True)
# Створення директорії, якщо потрібно
os.makedirs(os.path.dirname(output_path), exist_ok=True)
# Збереження
df.to_csv(output_path, index=False)
print(f"[✓] Cleaned data saved to: {output_path}")
if __name__ == "__main__":
symbol = "BTCUSDT"
interval = "1m"
input_csv = f"data/{symbol}_{interval}.csv"
output_csv = f"filtered/{symbol}_{interval}_filtered.csv"
filter_and_save_data(input_csv, output_csv)