MediumCreate List of dataframes For Loop Python | by Zeeshan Ali | Medium
Sitemap
Zeeshan Ali

Zeeshan Ali

I am a Python developer and I am here to share what i have learnt so far. Hope my posts will help you in your python development journey. www.letmeflutter.com

Create List of dataframes For Loop Python

1 min readJul 15, 2023

To create a list of DataFrames in Python, you can use the pandas library. Here’s an example of how you can create a list of DataFrames and then loop through them:

import pandas as pd
# Create an empty list to store the DataFrames
dataframes_list = []
# Create DataFrame 1
df1 = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
dataframes_list.append(df1)
# Create DataFrame 2
df2 = pd.DataFrame({'C': ['a', 'b', 'c'], 'D': ['d', 'e', 'f']})
dataframes_list.append(df2)
# Loop through the list of DataFrames
for df in dataframes_list:
# Perform operations on each DataFrame 'df'
print(df)
# Or apply any other desired operations
# ...

In this example, we create an empty list called dataframes_list to store the DataFrames. Then, we create two DataFrames (df1 and df2) using the pd.DataFrame() constructor, and we append them to the dataframes_list using the append() method.

Get Zeeshan Ali’s stories in your inbox

Join Medium for free to get updates from this writer.

After that, we use a for loop to iterate through each DataFrame in the dataframes_list and perform operations on them. In this case, we are simply printing each DataFrame, but you can apply any other operations or analysis that you need.

--

--

Zeeshan Ali
Zeeshan Ali

Written by Zeeshan Ali

I am a Python developer and I am here to share what i have learnt so far. Hope my posts will help you in your python development journey. www.letmeflutter.com