-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTidecalendarformatter.py
More file actions
67 lines (51 loc) · 2.01 KB
/
Tidecalendarformatter.py
File metadata and controls
67 lines (51 loc) · 2.01 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
## Claude
import pandas as pd
import pyperclip
from datetime import datetime
# Daten aus Zwischenablage lesen
clipboard_data = pyperclip.paste()
# In DataFrame umwandeln (Tab-getrennt, da aus Excel kopiert)
from io import StringIO
df = pd.read_csv(StringIO(clipboard_data), sep='\t')
# Spalten umbenennen falls nötig (anpassen an deine echten Spaltennamen)
df.columns = ['H_N', 'Wochentag', 'Datum', 'Uhrzeit', 'Scheitel']
# Datum als datetime konvertieren
df['Datum'] = pd.to_datetime(df['Datum'], format='%d.%m.%Y')
# Nach Datum gruppieren
grouped = df.groupby('Datum')
# Neue Datenstruktur aufbauen
daily_data = []
for datum, gruppe in grouped:
row = {
'Wochentag': gruppe.iloc[0]['Wochentag'],
'Datum': datum.strftime('%d.%m.%Y')
}
# Hochwasser extrahieren
hw = gruppe[gruppe['H_N'] == 'H'].reset_index(drop=True)
for i in range(len(hw)):
row[f'HW{i + 1}_Zeit'] = hw.loc[i, 'Uhrzeit']
row[f'HW{i + 1}_Scheitel'] = hw.loc[i, 'Scheitel']
# Niedrigwasser extrahieren
nw = gruppe[gruppe['H_N'] == 'N'].reset_index(drop=True)
for i in range(len(nw)):
row[f'NW{i + 1}_Zeit'] = nw.loc[i, 'Uhrzeit']
row[f'NW{i + 1}_Scheitel'] = nw.loc[i, 'Scheitel']
daily_data.append(row)
# DataFrame erstellen
daily_df = pd.DataFrame(daily_data)
# Spaltenreihenfolge festlegen (maximal 2 HW und 2 NW)
cols = ['Wochentag', 'Datum']
for i in range(1, 3): # Anpassen falls mehr als 2 HW/NW pro Tag
if f'HW{i}_Zeit' in daily_df.columns:
cols.extend([f'HW{i}_Zeit', f'HW{i}_Scheitel'])
if f'NW{i}_Zeit' in daily_df.columns:
cols.extend([f'NW{i}_Zeit', f'NW{i}_Scheitel'])
# Nur vorhandene Spalten verwenden
cols = [c for c in cols if c in daily_df.columns]
daily_df = daily_df[cols]
# Ergebnis in Zwischenablage kopieren (Tab-getrennt für Excel)
daily_df.to_clipboard(index=False, sep='\t')
print("✓ Daten wurden umformatiert und in die Zwischenablage kopiert!")
print(f"✓ {len(daily_df)} Tage verarbeitet")
print("\nVorschau:")
print(daily_df.head())