As I create new data frames for each customer I'd like to also create one giant data frame of all of them appended together.
I've created a function to group user data how I need it. Now I want to iterate over another data frame containing unique user keys and use those user keys to create data frames for each user. I'd then like to aggregate all those data frames into one giant data frame.
for index, row in unique_users.iterrows():
customer = user_df(int(index))
print(customer)
This function works as intended and prints a df for each customer
for index, row in unique_users.iterrows():
top_users = pd.DataFrame()
customer = user_df(int(index))
top_users = top_users.append(customer)
print(top_users)
This only prints out the last customer's df
I expect that as it iterates and creates a new customer df it will append that to the top_user df so at the end I have one giant top_user df. But instead it only contains that last customer's df.
top_usersinside your for loop. settop_users = pd.DataFrame()before your loop and it should perform as you expect.iterrows()to perform this aggregation, but it's impossible to tell without seeing the full code.iterrows. If you describe your situation more fully, some pandas wiz can probably guide you to the "pandas way" of doing thing - pandonic you might say. You should consider things like.iterrowsand.itertuplesas last resorts.df1 = pd.DataFrame(....)\n df2 = pd.DataFr..., and so on. I do strongly suspect that you don't want a DataFrame for each user, fwiw. Cheers!