Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One method for filtering through multiple data frames within a for loop is to store the data frames in a list and loop through the list using the for loop. Within the loop, filter out the desired data using standard filtering methods like .loc[] or .iloc[].

For example:

# create a list of data frames
df_list = [df1, df2, df3]

# loop through the list
for df in df_list:
    # filter the desired data
    filtered_data = df.loc[df['column'] == 'desired_value']

    # do something with the filtered data
    print(filtered_data)

This loop will iterate through each data frame in df_list, filter out the desired data, and print the resulting filtered data frame.