Home  >  Article  >  Backend Development  >  How Can I Efficiently Create Multiple Pandas DataFrames from a List?

How Can I Efficiently Create Multiple Pandas DataFrames from a List?

Barbara Streisand
Barbara StreisandOriginal
2024-11-21 07:01:08984browse

How Can I Efficiently Create Multiple Pandas DataFrames from a List?

Creating Multiple DataFrames in a Loop

To create a DataFrame for each value in a list of company names, use the following code:

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

This code will create a dictionary where the keys are the company names and the values are the corresponding DataFrames.

To access the DataFrame for a specific company, use the following syntax:

d[name]

For example, to access the DataFrame for the company "AA", use the following code:

d["AA"]

You can also use a loop to iterate over all the DataFrames in the dictionary:

for name, df in d.items():
    # operate on DataFrame 'df' for company 'name'

The above is the detailed content of How Can I Efficiently Create Multiple Pandas DataFrames from a List?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn