-1

I have image labels for my data, but I have reproduced 101 images for each image label that I have so in my CSV file I have Filename/Label file 1/3.4 file 2/5.6

I want 101 rows of file 1, 101 rows of file 2, and so on for a total of 1518 rows

I have no idea how to do it.

  • Have you actually tried any code yet? You will get much better answers/help if you have tried something but got stuck rather than simply saying you have no idea. – L.Clarkson Apr 26 '20 at 21:55
  • No I don't know how to approach this to be honest, I googled multiple sources and couldnt find anything, my skills are very basic in ML and python – Asood Muhammad Apr 26 '20 at 22:11

1 Answers1

0

I am a little unsure how exactly how the output should look, but this should give you enough to change to your needs:

This code will open an existing file and output the contents with each line duplicated:

with open('input.csv', 'r') as input_file:
    contents = input_file.read().splitlines()
input_file.close()

repeats = 101

with open('output_file.csv', 'w', newline='') as csvfile:
    writer = csv.writer(csvfile, delimiter=',')
    for name in contents:
        for i in range(0, repeats):
            line = name
            writer.writerow([line])
csvfile.close()
L.Clarkson
  • 492
  • 3
  • 12
  • Glad it worked. Just note that saying thank you in comments isn't considered good practice https://stackoverflow.com/help/someone-answers – L.Clarkson Apr 28 '20 at 18:42