Categories
Python Answers

How to create multiple dataframes in loop with Python Pandas?

Spread the love

Sometimes, we want to create multiple dataframes in loop with Python Pandas.

In this article, we’ll look at how to create multiple dataframes in loop with Python Pandas..

How to create multiple dataframes in loop with Python Pandas?

To create multiple dataframes in loop with Python Pandas, we can use dictionary comprehension.

For instance, we write

d = {name: pd.DataFrame() for name in companies}

to create data frames with DataFrame from the companies list with with key name with

{name: pd.DataFrame() for name in companies}

and assign the return data frame dictionary to d.

Conclusion

To create multiple dataframes in loop with Python Pandas, we can use dictionary comprehension.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *