Append Rows to pandas DataFrame in for Loop in Python (2 Examples) | Add to Existing & New Data Set

preview_player
Показать описание
Python code of this video:

import pandas as pd # Import pandas library in Python

data1 = pd.DataFrame({'x1':range(50, 56), # Create pandas DataFrame
'x2':range(10, 16),
'x3':range(36, 30, - 1)})
print(data1) # Print pandas DataFrame

for i in range(1, 4): # Append rows within for loop
print(data1) # Print updated DataFrame

data2 = pd.DataFrame(columns = ['x1', 'x2', 'x3']) # Create empty DataFrame with column names
print(data2) # Print empty DataFrame with column names
# Empty DataFrame
# Columns: [x1, x2, x3]
# Index: []

for i in range(5): # Append rows within for loop
print(data2) # Print updated DataFrame

Follow me on Social Media:

Рекомендации по теме
Комментарии
Автор

@matthias.statisticsglobe Hi sir....how to append set of csv files and each files containing data and the files are inside a folder...can you please do a video on this sir

kiya
Автор

How to insert dataframe into existing csv file using for loop. It's make duplicate date in csv file. And duplicate function not working in for loop. Can you make a video on this problem. Thanks

zahoorahmadkareemi