- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create a Pandas Dataframe by appending one row at a time
To create a Pandas DataFrame by appending one row at a time, we can iterate in a range and add multiple columns data in it.
Steps
Create a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.
Print the input DataFrame.
Iterate in a range of 10.
Assign values at different index with numbers.
Print the created DataFrame.
Example
import pandas as pd import random df = pd.DataFrame( { "x": [], "y": [], "z": [] } ) print "Input DataFrame:
", df for i in range(10): df.loc[i] = [i, random.randint(1, 10), random.randint(1, 10)] print "After appending row at a time:
", df
Output
Input DataFrame: Empty DataFrame Columns: [x, y, z] Index: [] After appending row at a time: x y z 0 0.0 9.0 3.0 1 1.0 2.0 1.0 2 2.0 5.0 5.0 3 3.0 7.0 1.0 4 4.0 2.0 10.0 5 5.0 5.0 4.0 6 6.0 1.0 3.0 7 7.0 4.0 2.0 8 8.0 2.0 2.0 9 9.0 10.0 8.0
- Related Articles
- Add a row at top in pandas DataFrame
- Python - Filter Pandas DataFrame by Time
- Create a Pipeline and remove a row from an already created DataFrame - Python Pandas
- How to add one row in an existing Pandas DataFrame?
- Create a Pandas DataFrame from lists
- Python Pandas - How to select rows from a DataFrame by passing row label
- Python Pandas - How to delete a row from a DataFrame
- Apply function to every row in a Pandas DataFrame
- How to get nth row in a Pandas DataFrame?
- How to add header row to a Pandas Dataframe?
- How to get the row count of a Pandas DataFrame?
- Updating a MySQL table row column by appending a value from user defined variable?
- How to create a pandas DataFrame using a list?
- How to create a pandas DataFrame using a dictionary?
- Create a Pivot Table as a DataFrame – Python Pandas

Advertisements