File size: 785 Bytes
5b804ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b306b77
5b804ab
 
 
 
 
 
 
 
 
 
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
import os 

import pandas as pd

ORIGINAL_FILE_PATH = os.path.realpath(os.path.join(os.path.dirname(__file__), "../originals/AmesHousing.txt"))
PROCESSED_FILE_PATH = os.path.realpath(os.path.join(os.path.dirname(__file__), "../AmesHousing.csv"))

def main():
    print(f"Preprocessing [{ORIGINAL_FILE_PATH}]...")

    df = pd.read_csv(ORIGINAL_FILE_PATH, sep="\t")

    print(f"[{df.shape[0]}] rows loaded over [{df.shape[1]}] columns")

    # Sanitizing the column names
    df.columns = df.columns.str.lower().str.replace(" ", "_").str.replace("/", "_").str.replace(".", "")

    # Set the index
    df = df.set_index("order")

    pd.DataFrame.to_csv(df, PROCESSED_FILE_PATH)
    print(f"Processed filed saved to [{PROCESSED_FILE_PATH}]...")


if __name__ == "__main__":
    main()