-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPreprocess_data.py
38 lines (25 loc) · 1.04 KB
/
Preprocess_data.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
import pandas as pd
import logging
import load_data
logging.basicConfig(level=logging.INFO)
def preprocess_data(df):
# Convert 'DATE' column to datetime format
df['DATE'] = pd.to_datetime(df['DATE'])
# Clean 'PRICE' column by converting non-numeric values to NaN
df['PRICE'] = pd.to_numeric(df['PRICE'], errors='coerce')
# Forward fill NaN values in 'PRICE'
df['PRICE'] = df['PRICE'].ffill()
# Drop rows with NaN values in 'PRICE' column
df = df.dropna(subset=['PRICE'])
return df
if __name__ == "__main__":
csv_folder = 'Market_Data_2013'
loaded_data = load_data.load_data(csv_folder)
# Preprocess each DataFrame
for file_name, df in loaded_data.items():
preprocessed_data = preprocess_data(df)
# Optional: Save the preprocessed data back to the dictionary
loaded_data[file_name] = preprocessed_data
logging.info(f"Preprocessed data for {file_name}:")
logging.info(preprocessed_data.head())
# Additional processing or saving to file can be done here