Suppose you have a DataFrame df with the following columns:
reference_column: column containing '1'sother_columns: other columns of your DataFrameTo create a new column with '1' for 3 rows for each '1' in the reference_column, you can use the following code:
main.py380 chars11 lines
Explanation of the code:
groupby the df DataFrame by reference_columnreference_column for each of the generated indexdf DataFrameThis code should generate a new column new_column that contains '1' for 3 rows for each '1' in reference_column.
gistlibby LogSnag