Python Pandas 脚本:重复打印 CSV 行并递增时间戳
import pandas as pd
读取文件
df = pd.read_csv('results-20230630t1147-processing.csv')
新建空DataFrame
new_df = pd.DataFrame(columns=df.columns)
遍历每一行
for index, row in df.iterrows(): # 获取重复次数 repeat_times = int(row[3])
# 重复打印
for i in range(repeat_times):
new_row = row.copy()
# 更新createdAt列
new_row[2] += i
# 添加到新的DataFrame中
new_df = new_df.append(new_row, ignore_index=True)
输出到文件
new_df.to_csv('training-data-prd-process-by-python.csv', index=False)
原文地址: https://www.cveoy.top/t/topic/o6Aa 著作权归作者所有。请勿转载和采集!