How to Create a Dataframe Row by Row in Python
To create a dataframe row by row in Python, you can use the DataFrame function from the pandas library.
The following example shows how to create a dataframe row by row in Python using the DataFrame function.
Using DataFrame() Function
We can use the DataFrame() function to create a dataframe row by row.
Suppose we have the following data:
import pandas as pd
data = [
{'Date': '03-03-2023', 'Product_code': 'A-105', 'Product_name': 'Headphones', 'Price': 100, 'Status': 1},
{'Date': '03-03-2023', 'Product_code': 'B-103', 'Product_name': 'Tablet', 'Price': 800, 'Status': 0},
{'Date': '04-03-2023', 'Product_code': 'A-106', 'Product_name': 'Monitor', 'Price': 350, 'Status': 1}
]
# Create dataframe
df = pd.DataFrame(data)
# Show dataframe
print(df)
Output: 👇️
Date Product_code Product_name Price Status
0 03-03-2023 A-105 Headphones 100 1
1 03-03-2023 B-103 Tablet 800 0
2 04-03-2023 A-106 Monitor 350 1
In this example, we use the DataFrame() function to create a dataframe df from the list of dictionaries data.
The output shows the dataframe created row by row using the DataFrame() function.
Conclusion
We can use the DataFrame() function from the pandas library to create a dataframe row by row in Python.