I have a dataframe with a column with item names and a column with a number. I would like to create a list with the item names repeated the number of times in the column.
My desired output is
I feel like I’m quite close with this code:
for index in df.iterrows(): for x in range(2): print(df.item)
However, I can’t find a way to replace 2 in range with the number out of the dataframe. df.numbers doesn’t seem to work.
As you said, your desired output is a
list, using @Michael’s comment, you can do this:
The output would be:
['cat', 'cat', 'dog', 'dog', 'dog', 'parrot', 'parrot', 'parrot', 'parrot']
Answered By – Shayan
Answer Checked By – Katrina (AngularFixing Volunteer)