I have a while looping using a counter to generate separate dataframes based on a variable in a column.
As this is in a while loop the dataframe is reassigned to the same name which overwrites what was there where as I want to keep the separate dataframes. I'm trying to find away to generate the dataframe names using the counter for the while loop
I have done a cluster analysis which has n clusters. The data has a column names 'Clusters' which has the cluster number that variable is assigned to. I used
numberofClusters = max(dataframe['Clusters'])
to get my number of clusters and my working while loop is as follows:
while ClusterNo < maxClusters:
Cluster = Clusters[Clusters['Cluster'] == ClusterNo]
ClusterNo += 1
Which will obviously keep overwriting 'Cluster' for the 10 iterations. But I want to keep all the separate dataframes. to that I have been using
while ClusterNo < maxClusters:
'Cluster' + str(ClusterNo) = Clusters[Clusters['Cluster'] == ClusterNo]
ClusterNo += 1
To try and generate a different dataframe for each cluster. But this is throwing a syntax error.
My expected output is for n amount of dataframes to be selected from the raw imported data each assigned to a different name