Add load_csv.py file to load to Pandas.
This commit is contained in:
parent
d546454164
commit
1967e5844a
28
load_csv.py
Normal file
28
load_csv.py
Normal file
@ -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()
|
||||
Loading…
Reference in New Issue
Block a user