Lesson 63 · Python Fundamentals
03 Inspect Columns and Summary Statistics in Pandas
In this lesson, you will learn how to look at and understand data using Python. Inspecting data helps you answer questions and solve problems. Let us get…
- CoursePython Fundamentals
- Lesson63 of 22
- Video3 min
- FormatJupyter notebook · 17 code cells
What you'll learn
Data
No separate download needed — the notebook creates or downloads everything it uses.
📓 Full notebook
Download .ipynb
Welcome to Inspecting Data in Python#
In this lesson, you will learn how to look at and understand data using Python.
Inspecting data helps you answer questions and solve problems.
Let us get started!
# Let us start with a simple list of numbers
numbers = [4, 9, 2, 7, 5]
print(numbers)
Understanding the type of your data#
Often, it helps to know what kind of data you are working with.
type() tells you the data type.
print(type(numbers))
# We can also check the type of other things
print(type(42))
print(type('hello'))
Finding the size of your data#
len() tells you how many items are in a list or another container.
This is handy when you do not know how much data you have.
print(len(numbers))
# What happens with an empty list?
empty = []
print(len(empty))
Looking at parts of your data#
You can use square brackets [ ] to pick out single items.
numbers[0] gives the first item. Python starts counting at zero!
first = numbers[0]
print(first)
# What if you want the last item?
last = numbers[-1]
print(last)
Accessing data safely#
If you try to access an index that does not exist, Python gives you an error.
Always check the length first if you are not sure.
# This will cause an IndexError if you go out of range
try:
print(numbers[10])
except IndexError:
print('That index is out of range!')
# Let us get user input and inspect it
user_input = input('Type any word: ')
print('Your text in upper case:', user_input.upper())
Slicing: Looking at pieces#
You can use numbers[1:4] to get a part of the list.
This grabs items from position 1 up to but not including 4.
middle = numbers[1:4]
print(middle)
# Let us look at a simple dictionary (like a mini-database)
person = {'name': 'Alex', 'age': 23, 'city': 'Maple Town'}
print(person)
# Keys help us look up specific values
print(person['city'])
# You can get a list of all keys and all values
print(person.keys())
print(person.values())
Mini-Project: Inspecting a List of Dictionaries#
Let us put it all together! Imagine you have a list of users.
We will learn how to inspect and summarize this data.
users = [
{'name': 'Anna', 'age': 29},
{'name': 'Ben', 'age': 35},
{'name': 'Cara', 'age': 22}
]
for user in users:
print('Name:', user['name'], '| Age:', user['age'])
# Let us summarize the ages
ages = [user['age'] for user in users]
print('Average age is:', sum(ages)/len(ages))
Recap: What did we learn?#
- You can use
type()andlen()for quick checks. - Indexes and keys help you pick out parts of your data.
- Slicing and comprehensions let you see sections and summaries.
- Practice makes you better at finding answers!
Well done!
Thanks for learning with us!#
If you enjoyed this lesson, please like the video, subscribe, and share it with a friend.
Comment below with your favorite data inspection tip!
See you in the next lesson!
Found this useful?
All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.



