Q&A 1 What are common data types in Python and R?
1.1 Explanation
Before you clean, visualize, or model data, itβs important to understand what types of values youβre working with β numeric, text, logical, or otherwise.
These data types affect how values are stored, displayed, and processed in both Python and R β and they play a major role in how functions behave.
1.2 Common Data Types in Python and R
Concept | Python (pandas / base) |
R (base ) |
Notes |
---|---|---|---|
Integer | int |
integer |
Use astype(int) or as.integer() |
Decimal Number | float |
numeric , double |
numeric is typically double in R |
Text / String | str , object (pandas) |
character |
Use astype(str) or as.character() |
Logical / Boolean | bool |
logical |
True/False in Python, TRUE/FALSE in R |
Date / Time | datetime64[ns] |
Date , POSIXct |
Use pd.to_datetime() or as.Date() |
Category | category |
factor |
Ideal for grouping and modeling |
Missing Values | NaN |
NA |
Use pd.isna() or is.na() |
Complex Numbers | complex |
complex |
Rare in typical data work |
List | list |
list |
Flexible containers |
Dictionary | dict |
named list , list() |
R lists can mimic dictionaries |
Tuple | tuple |
c() , list() |
No exact match β use vectors or lists |
β Knowing the common data types β and how to interpret them β lays the foundation for all future data work.