Create a Pandas Column using For Loop Last Updated : 03 Oct, 2025 Comments Improve Suggest changes 6 Likes Like Report In Pandas you can create a new column by iterating over an existing column (a Series) with a for loop, collecting computed values into a Python list and assigning that list back to the DataFrame as a new column.For Example: This example creates a new column that doubles the numbers in another column. Python import pandas as pd data = {'Number': [1, 2, 3]} df = pd.DataFrame(data) doubles = [] for n in df['Number']: doubles.append(n * 2) df['Double'] = doubles print(df) Output Number Double 0 1 2 1 2 4 2 3 6 Explanation:labels is created to store results.Each value in column "Number" is checked using %."Even" or "Odd" is appended to the list.A new column "Label" is created from that list.Let's see more examples to understand it better.More ExamplesExample 1: This example checks each voter’s age and creates a new column "Voter" showing whether the person is eligible to vote. Python import pandas as pd import numpy as np data = {'Voter_name': ['Geek1', 'Geek2', 'Geek3', 'Geek4', 'Geek5', 'Geek6', 'Geek7', 'Geek8'], 'Voter_age': [15, 23, 25, 9, 67, 54, 42, np.nan]} df = pd.DataFrame(data) status = [] for age in df['Voter_age']: if age >= 18: status.append("Yes") elif age < 18: status.append("No") else: status.append("Not Sure") df['Voter'] = status print(df) Output Voter_name Voter_age Voter0 Geek1 15.0 No1 Geek2 23.0 Yes2 Geek3 25.0 Yes3 Geek4 9.0 No4 Geek5 67.0 Yes5 Geek6 54.0 Yes6 Geek7 42.0 Yes7 Geek8 NaN Not SureExplanation:If age ≥ 18 -> "Yes".If age < 18 -> "No".If age is NaN -> "Not Sure".A new "Voter" column is created with results.Example 2: In this example, we classify salaries into "High" or "Low" categories and store them in a new column. Python import pandas as pd data = {'Employee': ['A', 'B', 'C', 'D'], 'Salary': [25000, 60000, 40000, 80000]} df = pd.DataFrame(data) category = [] for s in df['Salary']: if s >= 50000: category.append("High") else: category.append("Low") df['Category'] = category print(df) Output Employee Salary Category 0 A 25000 Low 1 B 60000 High 2 C 40000 Low 3 D 80000 High Explanation:Salaries ≥ 50,000 are labeled "High".Others are labeled "Low".New column "Category" stores these labels. Create Quiz Comment P PranchalKatiyar Follow 6 Improve P PranchalKatiyar Follow 6 Improve Article Tags : Python Python-pandas Python pandas-dataFrame pandas-dataframe-program Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like