#!python """ extract_and_merge_csv_cols.py is a script to extract a target column from a set of csvs and merge them into a single csv where each column name is the filename of the original csv. Usage: extract_and_merge_csv_cols.py ... """ import argparse import pandas as pd def main(): parser = argparse.ArgumentParser( description="Extract a target column from a set of csvs and merge them into a single CSV." ) parser.add_argument("target_col", help="The target column to extract") parser.add_argument("csvs", nargs="+", help="The csvs to extract from") args = parser.parse_args() dfs = [] for csv in args.csvs: df = pd.read_csv(csv) df = df[[args.target_col]].rename(columns={args.target_col: csv}) dfs.append(df) df = pd.concat(dfs, axis=1) df.to_csv("merged.csv", index=False) if __name__ == "__main__": main()