Data Types
Every value in a dataset has a type. Data science bugs are often type bugs — knowing Python's core types, and how to convert between them, is foundational to data cleaning and analysis.
2.1 What Is a Type?
A type is how Python represents different kinds of data — integers like 11, real numbers like 21.213, or words. Python checks the type of any value using the built-in type() function.
2.2 Integers (int) and Floats (float)
Integers are whole numbers, positive or negative. Floats are real numbers — they include integers, but also every value in between them. There's always another float between any two floats you pick.
This is why measurements, prices, and averages in a dataset are almost always floats, while counts (number of rows, number of customers) are integers.
2.3 Strings (str)
A string is a sequence of characters — text. Names, labels, and free-text fields in a dataset are all strings.
name = "Data Science"
print(type(name))
2.4 Type Casting
You can deliberately change the type of a value — this is called type casting. It's one of the most common things you'll do when cleaning messy data.
Enter any string, number, or boolean literal, select a target type, and observe Python's conversion result and explanation note.
int(1.1)2.5 Booleans (bool)
A Boolean can take on exactly two values: True or False — note the capital first letter. Booleans and numbers are closely linked: True behaves like 1, and False behaves like 0, when cast to int or float.
Key Takeaways
type()tells you the type of any value.- int = whole numbers; float = real numbers; str = text; bool = True/False.
- Floats are dense — there's always another float between any two floats.
- Type casting converts a value from one type to another (
int(),float(),str(),bool()). - int → float is always safe. float → int can lose information. A non-numeric string → int/float raises an error.