【问题标题】:Duplicating a row in CSV file 100 times在 CSV 文件中复制一行 100 次
【发布时间】:2020-08-10 08:54:27
【问题描述】:

我的数据有图像标签,但我为每个图像标签复制了 101 张图像 所以在我的 CSV 文件中我有 文件名/标签 文件 1/3.4 文件 2/5.6

我想要文件 1 的 101 行,文件 2 的 101 行,依此类推,总共 1518 行

我不知道该怎么做。

【问题讨论】:

  • 你真的尝试过任何代码吗?如果您尝试过某事但被卡住了,而不是简单地说您不知道,您会得到更好的答案/帮助。
  • 不,老实说,我不知道如何处理这个问题,我用谷歌搜索了多个资源并找不到任何东西,我的 ML 和 python 技能非常基础

标签: python image csv resnet


【解决方案1】:

我有点不确定输出应该是什么样子,但这应该足以满足您的需求:

此代码将打开一个现有文件并输出每行重复的内容:

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()

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-17
  • 2017-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-16
  • 1970-01-01
相关资源
最近更新 更多