Estrarre anno, mese e giorno della settimana
Usare l'accessor dt per creare feature.
Estrarre anno, mese e giorno della settimana è una lezione Data Science Academy gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Data Science Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Data Science Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
A Timestamp Holds a Lot
One datetime value packs a year, month, day, hour, and weekday inside it. The skill is pulling each piece out as its own column for analysis. 🧩
Meet the dt Accessor
On a datetime column, the dt accessor is your gateway. It exposes every date part as a simple attribute you can read or assign.
df["date"].dt # gateway to date partsPull Out the Year
Grabbing the year is one line. It is perfect for grouping sales or events into annual buckets.
df["year"] = df["date"].dt.yearMonth as a Number
The month attribute returns 1 through 12. Use it to compare the same month across different years.
df["month"] = df["date"].dt.monthMonth by Name
Numbers are fine for sorting, but charts read better with names. Use month_name to get January, February, and friends.
df["date"].dt.month_name() # 'March'Day of the Week
The dayofweek attribute numbers days from Monday=0 to Sunday=6. It is the backbone of any weekday analysis.
df["dow"] = df["date"].dt.dayofweekWeekday by Name
Want readable labels instead? Use day_name to turn each date into Monday, Tuesday, and so on for clean grouping.
df["date"].dt.day_name() # 'Friday'Spot the Weekend
Combine dayofweek with a comparison to flag weekends. This boolean column instantly splits work days from rest days.
df["weekend"] = df["date"].dt.dayofweek >= 5Quarter and Day of Year
Two more handy parts: quarter for Q1 to Q4 reporting, and dayofyear for tracking position within a single year.
df["date"].dt.quarter
df["date"].dt.dayofyearHours and Minutes Too
If your data has time, the dt accessor also exposes hour and minute. That makes it easy to study peak activity windows.
df["hour"] = df["date"].dt.hourFeatures Power Analysis
Each extracted part becomes a feature you can group by or feed to a model. This is how raw timestamps turn into insight.
df.groupby(df["date"].dt.month).size()Quick Check
You want to flag rows that fall on Saturday or Sunday.
Recap: Unpack Any Date
You used the dt accessor to pull year, month, weekday, quarter, and hour from timestamps, turning each into a feature ready for grouping. 🗓️
Domande Frequenti
La lezione «Estrarre anno, mese e giorno della settimana» è gratuita?
Sì — il testo completo di «Estrarre anno, mese e giorno della settimana» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Data Science Academy, passa a CoddyKit PRO. Il corso Data Science Academy include 4 lezioni in totale.
Cosa imparerò in «Estrarre anno, mese e giorno della settimana»?
Usare l'accessor dt per creare feature. Eserciti Data Science Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Data Science Academy?
Non è richiesta alcuna esperienza precedente. Data Science Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.
Quanto tempo richiede la lezione «Estrarre anno, mese e giorno della settimana»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Data Science Academy?
Sì. Ogni lezione Data Science Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Analizzare stringhe come datetime
- Estrarre anno, mese e giorno della settimana
- Ricampionare su base giornaliera o mensile
- Fusi orari e intervalli di date