Creare un DataFrame da zero
Da dizionari, liste e array.
Creare un DataFrame da zero è 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.
Why Build Your Own
Before loading real files, building a small DataFrame by hand lets you test ideas and learn the structure with zero setup. 🧪
Import pandas First
Every project starts the same way: import pandas under the nickname pd. That short alias is a universal convention you will see everywhere.
import pandas as pdFrom a Dictionary of Columns
The most common recipe is a dict where each key is a column name and each value is a list of that column's data.
df = pd.DataFrame({"name": ["Ada", "Lin"], "age": [36, 41]})Keys Become Headers
With the dict approach, the dictionary keys turn into your column headers automatically. Naming columns is as easy as naming keys.
From a List of Rows
You can also pass a list of rows and supply the column names separately. Handy when your data already arrives row by row.
pd.DataFrame([["Ada", 36], ["Lin", 41]], columns=["name", "age"])From a List of Dicts
A list of dicts works too, with one dict per row. Missing keys simply become blanks, which is great for uneven records.
pd.DataFrame([{"name": "Ada"}, {"name": "Lin", "age": 41}])From a NumPy Array
Have a NumPy array of numbers? Pass it straight in and add column names. This bridges fast NumPy math with labeled tables.
pd.DataFrame(arr, columns=["x", "y"])Set the Index on Creation
Pass an index argument to label your rows the moment you build the frame, instead of relying on default 0, 1, 2 numbers.
pd.DataFrame(data, index=["r1", "r2"])Control the Column Order
Want columns in a specific order? Pass a columns list and pandas arranges them exactly as you list, ignoring dict ordering quirks.
pd.DataFrame(data, columns=["age", "name"])Lengths Must Match
Every column you provide must have the same length. Mismatched list sizes raise an error, so keep your columns even.
Peek at What You Built
After building, glance at dtypes to confirm pandas inferred sensible types like int for ages and object for names.
df.dtypesQuick Check
Pick the building block behind the most common DataFrame recipe.
Recap: Many Ways In
Dicts, lists, list-of-dicts, or NumPy arrays all become a DataFrame. Pick whatever matches the shape of your data. 🛠️
Domande Frequenti
La lezione «Creare un DataFrame da zero» è gratuita?
Sì — il testo completo di «Creare un DataFrame da zero» è 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 un DataFrame da zero»?
Da dizionari, liste e array. 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 «Creare un DataFrame da zero»?
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
- Righe, colonne e indice
- Creare un DataFrame da zero
- head, info e describe
- Aggiungere, rinominare ed eliminare colonne