From 1967e5844a38584cb0543e57af0f2dd649df9255 Mon Sep 17 00:00:00 2001 From: Nick Hepler Date: Mon, 19 Aug 2024 10:52:19 -0400 Subject: [PATCH] Add load_csv.py file to load to Pandas. --- load_csv.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 load_csv.py diff --git a/load_csv.py b/load_csv.py new file mode 100644 index 0000000..5227344 --- /dev/null +++ b/load_csv.py @@ -0,0 +1,28 @@ +import pandas as pd +import argparse +import sys + +def load_csv(file_path): + """Load a CSV file into a pandas DataFrame and print it.""" + try: + df = pd.read_csv(file_path) + print(df) + except FileNotFoundError: + print(f"Error: The file at {file_path} does not exist.") + except pd.errors.EmptyDataError: + print(f"Error: The file at {file_path} is empty.") + except pd.errors.ParserError: + print(f"Error: There was a parsing error with the file at {file_path}.") + except Exception as e: + print(f"An unexpected error occurred: {e}") + +def main(): + """Main function to handle command-line arguments and load the CSV file.""" + parser = argparse.ArgumentParser(description='Load a CSV file into a pandas DataFrame.') + parser.add_argument('file_path', type=str, help='Path to the CSV file.') + args = parser.parse_args() + + load_csv(args.file_path) + +if __name__ == '__main__': + main()