pandas with reading file

41 Views Asked by At

I'm trying to read csv file stored in my computer using pandas. This is my code, but I have a problem like the screenshot.

file_path = "/Users/shazelpark/laptop_pricing_dataset_mod1.csv"
df = pd.read_csv(file_path, header=0)

I'd like to read the file without problem. Please share your solutions.

Thanks

1

There are 1 best solutions below

0
Mahboob Nur On BEST ANSWER

Try like this

import pandas as pd

file_path = "/Users/shazelpark/laptop_pricing_dataset_mod1.csv"

try:
    df = pd.read_csv(file_path, header=0)
    print(df.head())  
except FileNotFoundError:
    print("File not found. Please check the file path.")
except pd.errors.EmptyDataError:
    print("The file appears to be empty.")
except pd.errors.ParserError:
    print("There was an issue parsing the file. Please check the file format.")