Series and DataFrame Fundamentals
Create and inspect Pandas data structures from various sources.
Series and DataFrame Fundamentals is a free Python Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is Pandas?
Pandas provides Series (1-D labelled array) and DataFrame (2-D labelled table) built on NumPy, optimised for data analysis.
import pandas as pd
s = pd.Series([10, 20, 30], index=["a","b","c"])
print(s)
# a 10
# b 20
# c 30Creating a Series
Create a Series from a list, dict, or scalar. The index defaults to 0-based integers.
import pandas as pd
# From list:
s1 = pd.Series([1, 2, 3])
# From dict (keys become index):
s2 = pd.Series({"x": 10, "y": 20})
# Scalar (broadcast):
s3 = pd.Series(5, index=range(4))
print(s3) # 0 5 / 1 5 / 2 5 / 3 5Creating a DataFrame
Create a DataFrame from a dict of lists, a list of dicts, or a NumPy array.
import pandas as pd
df = pd.DataFrame({
"name": ["Alice","Bob","Carol"],
"age": [30, 25, 35],
"score":[95.5, 87.0, 92.3]
})
print(df)Basic Inspection
head(), tail(), shape, dtypes, info(), describe() — your first steps with any new dataset.
import pandas as pd
df = pd.read_csv("data.csv")
print(df.head()) # first 5 rows
print(df.shape) # (rows, cols)
print(df.dtypes) # column types
print(df.describe()) # count, mean, std, min...Column Access
Access a column with dot notation or square brackets. Dot notation fails for column names with spaces or that clash with DataFrame attributes.
import pandas as pd
df = pd.DataFrame({"age":[30,25], "city":["NY","LA"]})
print(df["age"]) # preferred
print(df.age) # also works if name is simple
print(df[["age","city"]]) # multiple columnsIndex Basics
The index labels rows. It defaults to 0, 1, 2... but can be set to any hashable values.
import pandas as pd
df = pd.DataFrame({"val":[10,20,30]}, index=["a","b","c"])
print(df.loc["b"]) # row with label b
print(df.index) # Index(['a','b','c'])
# Reset to default integer index:
df.reset_index(drop=True, inplace=True)Adding and Removing Columns
Assign to a new key to add a column. Use drop() to remove one.
import pandas as pd
df = pd.DataFrame({"a":[1,2,3],"b":[4,5,6]})
df["c"] = df["a"] + df["b"] # new column
df.drop(columns=["b"], inplace=True)
print(df)Series Alignment
When combining Series, Pandas aligns by index. Missing matches produce NaN.
import pandas as pd
s1 = pd.Series([1,2,3], index=["a","b","c"])
s2 = pd.Series([10,20], index=["b","c"])
print(s1 + s2)
# a NaN
# b 12.0
# c 23.0to_dict and to_list
Convert a DataFrame or Series back to standard Python structures for export or inspection.
import pandas as pd
df = pd.DataFrame({"x":[1,2],"y":[3,4]})
print(df.to_dict("records"))
# [{'x': 1, 'y': 3}, {'x': 2, 'y': 4}]
print(df["x"].to_list())
# [1, 2]Reading Files
Pandas reads CSV, Excel, JSON, Parquet, and SQL directly into DataFrames.
import pandas as pd
df_csv = pd.read_csv("data.csv")
df_excel = pd.read_excel("data.xlsx", sheet_name="Sheet1")
df_json = pd.read_json("data.json")
df_parq = pd.read_parquet("data.parquet")
# pd.read_sql("SELECT * FROM table", conn)Writing Files
Export DataFrames to CSV, Excel, JSON, and Parquet.
import pandas as pd
df = pd.DataFrame({"a":[1,2],"b":[3,4]})
df.to_csv("out.csv", index=False)
df.to_json("out.json", orient="records")
df.to_parquet("out.parquet")Quick Check
What does df.describe() return?
Recap
A Series is a 1-D labelled array; a DataFrame is a 2-D labelled table. Access columns with df["col"]. Use head(), describe(), info() for quick inspection. Read/write CSV, Excel, JSON, and Parquet with built-in functions.
Frequently asked questions
Is the “Series and DataFrame Fundamentals” lesson free?
Yes — the full text of “Series and DataFrame Fundamentals” is free to read here on the web, and the Python Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python Academy course, upgrade to CoddyKit PRO.
What will I learn in “Series and DataFrame Fundamentals”?
Create and inspect Pandas data structures from various sources. You practise Python Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Python Academy?
No prior experience is required. Python Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Series and DataFrame Fundamentals” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Python Academy lesson?
Yes. Every Python Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Series and DataFrame Fundamentals
- Indexing, Filtering, and Boolean Masks
- GroupBy, Aggregation, and Pivot Tables
- Merging, Joining, and Data Cleaning