python - Pandas efficiently repeat rows -



python - Pandas efficiently repeat rows -

i know typically replication of rows horrible performance, why answers on stackoverflow don't explain how suggest improve alternatives - utilize case, need that.

i have table replication weights,

id some_value weight 1 2 5 2 2 3 b 1 4 3 3

where need repeat each row weight value. think of huge info frame. efficient way accomplish this?

expected output:

id some_value weight 1 2 5 1 2 5 1 2 5 1 2 5 1 2 5 2 2 2 2 3 b 1 4 3 3 4 3 3 4 3 3

perhaps treat weighted array:

def weighted_array(arr, weights): zipped = zip(arr, weights) weighted_arr = [] in zipped: j in range(i[1]): weighted_arr.append(i[0]) homecoming weighted_arr

the returned weighted_arr have each element in arr, repeated 'weights' number of times.

python pandas

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -