Data Manipulation
Pandas Basics
1 min read
Published Sep 29 2025, updated Aug 17 2026
Guide Sections
Guide Comments
Renaming Columns
You can rename all columns at once or specific ones.
# Rename all columns by assigning a new listdf.columns = ["Name", "Age", "Salary"]# Rename selected columnsdf.rename(columns={"old_name": "new_name"}, inplace=True)Use .rename() when you only want to change a few columns.
Selecting Columns by Data Type
.select_dtypes() helps filter numeric, categorical, or boolean columns.
# Select only numeric columnsdf_numeric = df.select_dtypes(include=["number"])# Select only object (string) columnsdf_object = df.select_dtypes(include=["object"])# Exclude float columnsdf_no_float = df.select_dtypes(exclude=["float"])Converting to NumPy
Access the underlying NumPy representation of the DataFrame.
# returns a 2D NumPy arraydf_array = df.valuesThis strips column and index labels (just raw data).
Replacing Data
.replace() can substitute values in the whole DataFrame or specific columns.
# Replace a single valuedf.replace(0, pd.NA, inplace=True)# Replace multiple valuesdf.replace([1,2,3], [10,20,30], inplace=True)# Replace in a single columndf["col"].replace("?", "Unknown", inplace=True)Changing Data Types
.astype() is used to convert a column to a new data type.
# Convert a column to intdf["Age"] = df["Age"].astype(int)# Convert multiple columnsdf = df.astype({"Age": "int32", "Salary": "float"})Mapping Data
.map() can apply a function, dictionary mapping, or Series to each element in that column.
df["col"].map({"M": "Male", "F": "Female"})This replaces "M" with "Male" and "F" with "Female" in that column.
You can also pass a function:
df["col"].map(str.lower)applymap() can apply a function elementwise to every single cell in the entire DataFrame.
df.applymap(str.upper)Converts every value in the DataFrame to uppercase strings.