我正在尝试使用 pandas 读取存储在我的计算机中的 csv 文件。 这是我的代码,但我有一个像屏幕截图一样的问题。
file_path = "/Users/shazelpark/laptop_pricing_dataset_mod1.csv"
df = pd.read_csv(file_path, header=0)
我想毫无问题地阅读该文件。 请分享您的解决方案。
谢谢
尝试这样
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.")