I have the following dataframe
col1 col2 col3
0 str9 47 55
1 str8 43 51
2 str9 46 52
3 str2 42 56
and the following string array generated from df.col1.unique()
strings = ['str9', 'str8', 'str9', 'str2']
I want to create new dataframes to manage the amount of data I'm manipulating where each new dataframe represents df[df.col1 == strings[0]]
, df[df.col1 == strings[1]]
, and so on throughout all values in strings
I would like to name them based off of their values in strings too, so we would have
df_str9 = df[df.col1 == strings[0]]
I know I can loop through the string to access each value in strings, but how do I create the dataframe so it has the name requirements as listed?
Something like:
data_file = pd.DataFrame(data = ([['str9', 47, 55], ['str8', 43, 51], ['str9', 46, 52] , ['str2', 42, 56]] ), columns = (['col1', 'col2', 'col3']))
for string in strings:
df_string = df[df.col1 == string]