OutageGen/load_csv.py
2024-08-19 10:52:19 -04:00

29 lines
952 B
Python

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()