Datasets:
La-matrice
commited on
Commit
•
33b7338
1
Parent(s):
5b9ba53
Update normalization.py
Browse files- normalization.py +1 -43
normalization.py
CHANGED
@@ -1,8 +1,3 @@
|
|
1 |
-
import pandas as pd
|
2 |
-
import pyarrow as pa
|
3 |
-
import pyarrow.parquet as pq
|
4 |
-
|
5 |
-
# Define normalization parameters
|
6 |
norm_params = {
|
7 |
'LAT': {'min_val': -66.817333, 'max_val': 51.055833},
|
8 |
'LON': {'min_val': -178.116667, 'max_val': 171.358333},
|
@@ -15,41 +10,4 @@ norm_params = {
|
|
15 |
}
|
16 |
|
17 |
def normalize_column(column, min_val, max_val):
|
18 |
-
|
19 |
-
# Ensure column is treated as float for division to work properly.
|
20 |
-
return (column.astype('float64') - min_val) / (max_val - min_val)
|
21 |
-
|
22 |
-
# Load the dataset in chunks
|
23 |
-
dataset_path = 'C:/Users/View/Desktop/oetem/dataset/dataset.parquet'
|
24 |
-
parquet_file = pq.ParquetFile(dataset_path)
|
25 |
-
|
26 |
-
# Determine the output file path
|
27 |
-
output_path = 'C:/Users/View/Desktop/oetem/dataset/dataset_normalized.parquet'
|
28 |
-
|
29 |
-
# Initialize variables for writing
|
30 |
-
writer = None
|
31 |
-
schema = None
|
32 |
-
|
33 |
-
# Process and normalize chunks
|
34 |
-
for i in range(parquet_file.num_row_groups):
|
35 |
-
table = parquet_file.read_row_group(i, columns=list(norm_params.keys()) + [' T'])
|
36 |
-
chunk = table.to_pandas()
|
37 |
-
|
38 |
-
# Normalize the columns
|
39 |
-
for col, params in norm_params.items():
|
40 |
-
chunk[col] = normalize_column(chunk[col], min_val=params['min_val'], max_val=params['max_val'])
|
41 |
-
|
42 |
-
# Convert the DataFrame back to a PyArrow Table for writing
|
43 |
-
#table = pa.Table.from_pandas(chunk)
|
44 |
-
table = pa.Table.from_pandas(chunk, preserve_index=False)
|
45 |
-
|
46 |
-
# If first chunk, initialize the writer with the schema
|
47 |
-
if writer is None:
|
48 |
-
schema = table.schema
|
49 |
-
writer = pq.ParquetWriter(output_path, schema)
|
50 |
-
|
51 |
-
writer.write_table(table)
|
52 |
-
|
53 |
-
# Close the writer to finalize the file
|
54 |
-
if writer is not None:
|
55 |
-
writer.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
norm_params = {
|
2 |
'LAT': {'min_val': -66.817333, 'max_val': 51.055833},
|
3 |
'LON': {'min_val': -178.116667, 'max_val': 171.358333},
|
|
|
10 |
}
|
11 |
|
12 |
def normalize_column(column, min_val, max_val):
|
13 |
+
return (column.astype('float64') - min_val) / (max_val - min_val)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|