split.py 867 B

123456789101112131415161718192021222324252627
  1. import pandas as pd
  2. import os
  3. import sys
  4. sys.path.append("/home/vangogh/software/FuzzScene/code/")
  5. import Constants
  6. # 读取csv文件
  7. df = pd.read_csv(Constants.CARLA_RADAR_LABEL_OUTPUT_PATH + "label_test.csv")
  8. # 获取文件总行数
  9. row_num = len(df)
  10. # 确定每个小文件要包含的数据量
  11. step = 1250
  12. index = 0
  13. for start in range(0, row_num, step):
  14. stop = start + step
  15. filename = Constants.CARLA_RADAR_LABEL_OUTPUT_PATH + "label_test_"+str(index)+".csv"
  16. d = df[start: stop]
  17. print("[" + os.path.basename(__file__) + ", Line " + str(sys._getframe().f_lineno) + ", " + sys._getframe().f_code.co_name + "] ", "Saving file : " + filename + ", data size : " + str(len(d)))
  18. d.to_csv(filename, index=None)
  19. index += 1
  20. # 输出如下
  21. # Saving file : ./small_0-500.csv, data size : 500
  22. # Saving file : ./small_500-1000.csv, data size : 500