compile_csv.py 584 B

1234567891011121314151617181920212223
  1. #!/usr/bin/env python3
  2. import sys, glob, pandas
  3. # get command line arguments
  4. if len(sys.argv) < 2:
  5. print('usage:', sys.argv[0], ' input_dir output_file')
  6. sys.exit(-1)
  7. input_dir = sys.argv[1]
  8. output_file = sys.argv[2]
  9. # read csv files and append dataframe
  10. df = pandas.DataFrame()
  11. for csv_file in glob.glob(input_dir + '*.csv'):
  12. try:
  13. file_df = pandas.read_csv(csv_file, sep=';')
  14. df = df.append(file_df, ignore_index=True)
  15. except:
  16. print('warning:', csv_file, 'is empty')
  17. # export dataframe to csv
  18. df.to_csv(output_file, index=False, sep=';')