Python: Wochentag aus NumPy datetime64-Arrays extrahieren mit UliEngineering
Du kannst leicht die Wochentagskomponente aus NumPy datetime64-Arrays mit der UliEngineering-Python-Bibliothek extrahieren:
extract_day_of_week.py
import numpy as np
from UliEngineering.Utils.Date import *
# datetime64-Array erstellen
dates = np.array(['2024-01-15', '2024-06-20', '2024-12-31'], dtype='datetime64[D]')
# Wochentag extrahieren (0 = Montag, 6 = Sonntag)
days = extract_day_of_week(dates)
print(f"Daten: {dates}")
print(f"Wochentag (0=Mo, 6=So): {days}")Beispielausgabe
extract_day_of_week_output.txt
Daten: ['2024-01-15' '2024-06-20' '2024-12-31']
Wochentag (0=Mo, 6=So): [0 3 2]Die Funktion extract_day_of_week() gibt ein NumPy-Array zurück, das den Wochentag (0–6, wobei 0 Montag und 6 Sonntag ist) für jeden datetime64-Wert im Eingabearray enthält.
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow