I have a Pandas dataframe with about 600 rows, with one column called "PAGE_NAME" that contains 8 unique string values. These are the 8 unique string values in this column:
my_list_of_strings = ['Demographics', 'SummaryMeasuresOfHealth', 'LeadingCausesOfDeath', 'MeasuresOfBirthAndDeath', 'RelativeHealthImportance', 'VunerablePopsAndEnvHealth', 'PreventiveServicesUse', 'RiskFactorsAndAccessToCare']
There are 6 other columns in this dataframe.
What I'd like to do is create 8 new dataframes, one for each of these strings, where each of the 8 new dataframes will include just the rows where a given string is in the "PAGE_NAME" column.
I would like to assign each of the 8 new dataframes a variable name that includes the string: something like Demographics_df, SummaryMeasuresOfHealth_df, etc....
I was able to write a function (below) that creates a list of the dataframes, but (1) I don't know how to extract the 8 separate dataframes and (2) I don't know how to give them names with the appropriate string as part of of the variable name.
def make_pagename_dataframes(page_name_list):
list_of_dfs = []
for i in page_name_list:
list_of_dfs.append(original_df.loc[original_df['PAGE_NAME'] == i])
return list_of_dfs
list_of_new_dfs = make_pagename_dataframes(my_list_of_strings)