I'm not sure if this question has been asked before, but I have a dataframe with > 2M rows and there is a column that identifies which location each transaction occurred at. I am trying to filter down and create a new dataframe for each Location code. I can filter that dataframe, but the problem I'm running into is having a function that changes the name of each new dataframe so that I end up with each one having a distinct name. I have some code to show what I have so far:
df = pd.DataFrame({'location':[1, 2, 3, 4, 5], 'col2': [234.34, 34.80, 23.65, 24.23, 12.00]})
filter_array = []
def new_df_for_columns(df, column, filter_array):
i = 0
for column in filter_array:
newdf = df[df[column] == filter_array[i]]
i += 1
return newdf.head()
So in this case, I need to change "newdf" for each new created dataframe.