-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvert_data.py
More file actions
53 lines (43 loc) · 1.42 KB
/
convert_data.py
File metadata and controls
53 lines (43 loc) · 1.42 KB
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
import re
import geopandas
import pandas as pd
META_COLUMNS = [
'id',
'date_connect',
'date_decom',
'capacity_kW',
'rotor_diam_m',
'hub_height_m',
'manufacturer',
'type',
'auth',
'location',
'district',
'district_no',
'X_UTM_32_ETRS89',
'Y_UTM_32_ETRS89',
'coord_origin',
]
def _extract_year(value) -> str | None:
match = re.match(r'^(\d{4})', str(value))
return match.group(1) if match else None
def _collapse_to_years(frame: pd.DataFrame) -> pd.DataFrame:
numeric_cols = [col for col in frame.columns if _extract_year(col)]
if not numeric_cols:
return frame
numeric_df = frame[numeric_cols].copy()
numeric_df.columns = [_extract_year(col) for col in numeric_df.columns]
numeric_df = numeric_df.groupby(by=numeric_df.columns, axis=1).sum(numeric_only=True, min_count=1)
return pd.concat([frame.drop(columns=numeric_cols), numeric_df], axis=1)
df = pd.read_excel('data_2025-01.xlsx', skiprows=10, header=0, usecols='A:CR')
rename_limit = min(len(META_COLUMNS), len(df.columns))
column_map = {df.columns[i]: META_COLUMNS[i] for i in range(rename_limit)}
df = df.rename(columns=column_map)
df = _collapse_to_years(df)
points = geopandas.points_from_xy(
x=df.X_UTM_32_ETRS89,
y=df.Y_UTM_32_ETRS89,
crs="EPSG:25832",
)
gdf = geopandas.GeoDataFrame(df, geometry=points).to_crs("EPSG:4326")
gdf.to_file('wt_2025jan.json', driver='GeoJSON')