Sample of reading CSV file with python
CSVサンプル
Name,Age Alice,25 Bob,30 Charlie,22
import csv def read_csv_file(file_path): try: with open(file_path, 'r', newline='') as csvfile: csv_reader = csv.DictReader(csvfile) # 各行のデータを利用 for row in csv_reader: name = row['Name'] age = int(row['Age']) print(f"{name} is {age} years old.") except FileNotFoundError: print("File not found.") except Exception as e: print("Error:", e) if __name__ == "__main__": csv_file_path = "example.csv" # CSVファイルのパスを指定してください read_csv_file(csv_file_path)
コメント
コメントを投稿