0Pricing
Data Science Academy · Lezione

Creare feature da date e testo

Estrarre informazioni utili dai campi grezzi.

Creare feature da date e testo è una lezione Data Science Academy gratuita su CoddyKit. Questa è la lezione 4 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.

Raw Fields Hide Signal

A timestamp or a free-text note holds rich clues a model cannot read directly. Feature engineering pulls that signal into usable columns. 🔍

Parse the Date First

Before mining a date, convert the string with to_datetime. Only a real datetime exposes the handy parts you want to extract.

df['ts'] = pd.to_datetime(df['ts'])

The dt Accessor

The dt accessor unlocks date parts on a datetime column. Reach for it to grab year, month, day, and more in one line.

df['year'] = df['ts'].dt.year
df['month'] = df['ts'].dt.month

Day of Week

Pull dayofweek to capture weekly rhythm, where Monday is 0 and Sunday is 6. Behavior often shifts a lot by weekday.

df['weekday'] = df['ts'].dt.dayofweek

Weekend Flag

Turn the weekday into a simple boolean: is this a weekend? Such yes-or-no flags are easy for models to learn from.

df['is_weekend'] = df['ts'].dt.dayofweek >= 5

Cyclical Time

Hour 23 sits right next to hour 0, yet the numbers look far apart. Cyclical encoding with sine and cosine fixes that wrap-around.

Text: Length and Counts

Start simple with text. The character length of a review or its word count is often a surprisingly strong feature.

df['len'] = df['review'].str.len()
df['words'] = df['review'].str.split().str.len()

Contains a Keyword

Flag whether text holds a key term using str.contains. A column for words like refund can capture clear intent.

df['has_refund'] = df['review'].str.contains('refund')

Bag of Words

To use words themselves, count them. A bag-of-words turns text into one column per term holding how often it appears.

from sklearn.feature_extraction.text import CountVectorizer
X = CountVectorizer().fit_transform(df['review'])

TF-IDF Weighs Words

Plain counts overrate common words. TF-IDF rewards terms that are frequent in one row yet rare overall, so the distinctive words stand out.

from sklearn.feature_extraction.text import TfidfVectorizer
X = TfidfVectorizer().fit_transform(df['review'])

Avoid Leaky Features

Never build a feature from information unavailable at prediction time. A leaky column inflates scores in testing, then fails in the real world.

Quick Check

You have a datetime column and want the weekday number. What do you use?

Recap: Date and Text Features

You mined raw fields into signal: parse dates then use dt for parts and flags, and turn text into lengths, keyword flags, or word counts. 🎉

Domande Frequenti

La lezione «Creare feature da date e testo» è gratuita?

Sì — il testo completo di «Creare feature da date e testo» è 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 «Creare feature da date e testo»?

Estrarre informazioni utili dai campi grezzi. 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 4 di 4.

Quanto tempo richiede la lezione «Creare feature da date e testo»?

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

  1. Raggruppare i numeri in categorie
  2. Codificare le colonne categoriche
  3. Scalare e normalizzare i numeri
  4. Creare feature da date e testo
← Torna a Data Science Academy