Skip to content

Instantly share code, notes, and snippets.

@dustindorroh
Created December 27, 2015 10:35
Show Gist options
  • Save dustindorroh/3a36b92c95325cac99b6 to your computer and use it in GitHub Desktop.
Save dustindorroh/3a36b92c95325cac99b6 to your computer and use it in GitHub Desktop.
Concatenate csv files using pandas DataFrames into one file
#!/usr/bin/env python2
'''
Concatenate csv files using pandas DataFrames into one file
:author: Dustin Dorroh <[email protected]>
'''
import argparse
import pandas as pd
import os
def parse_args():
"""
Use argparse module. Santize options and return the parser.
:return:
args
"""
parser = argparse.ArgumentParser(description="Concatenate DataFrame csv files into one file")
parser.add_argument("-i", "--input-files", dest="input_files", nargs='*', help="Input CSV files",required=True)
parser.add_argument("-o", "--output-file", dest="output_file", help="Output CSV file", type=str,required=True)
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
print(args)
df = pd.concat(map(pd.read_csv,args.input_files))
df.to_csv(args.output_file,index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment