I have this code below unique_allocations is a DataFrame of 4 rows that has different numbers let's say [1,2,3,4]. Then as we can see for every row of filered_processed_full I'm duplicated the row 4 times then trying to set allocation_columns to unique_allocations. So for example if curr_df =
[[taco, allocation], [0 , 1], [0 , 1], [0 , 1], [0 , 1]] (we'll just pretend that the first row is column names and subsequent rows are values for row). I'd like to transform that into curr_df =
[[taco, allocation], [0 , 1], [0 , 2], [0 , 3], [0 , 4]], where in this example allocation_columns is allocation. How do I set it this way? Currently the print() is just printing curr_df wit the columns I wanted unchanged.
import pandas as pd
for idx, row in filtered_processed_full.iterrows():
curr_df = pd.DataFrame()
for i in range (4):
curr_df = curr_df.append(row)
curr_df[allocation_columns] = unique_allocations
with pd.option_context('display.max_rows', None,
'display.max_columns', None,
'display.precision', 3,
):
print(curr_df[allocation_columns])
filtered_processed_full. In the actual version of your code, you definecurr_dfinside the outer for loop, which means that in each iteration, the previous one is going to be overwritten. Is this your intention or a mistake? a more complete example of your output will help.