Python讀取CSV文件的方法有以下幾種:
import csv
with open('file.csv', 'r') as file:
reader = csv.reader(file)
for row in reader:
print(row)
import pandas as pd
data = pd.read_csv('file.csv')
print(data)
import numpy as np
data = np.genfromtxt('file.csv', delimiter=',')
print(data)
with open('file.csv', 'r') as file:
for line in file:
row = line.strip().split(',')
print(row)
以上是Python讀取CSV文件的常用方法,根據(jù)具體的需求和數(shù)據(jù)結(jié)構(gòu),可以選擇合適的方法來讀取和處理CSV文件。