- pandas
import pandas as pd
ann = pd.read_csv('csv/sun37.csv')
for i, row in ann.iterrows():
print(row)
每一行的数据 都带有了表头属性名
name wall
r 148
g 65
b 137
Name: 0, dtype: object
name floor
r 255
g 116
b 69
Name: 1, dtype: object
可以这样用
label_name = row['name']
r = row['r']
g = row['g']
b = row['b']
label[label_name] = [int(r), int(g), int(b)]
- csv
import csv
with open('csv/ade150.csv', 'r') as csv_file:
reader = csv.reader(csv_file)
for i, row in enumerate(reader):
if i > 0: # 跳过第一行
print(row) # list
['wall', '148', '65', '137']
['floor', '255', '116', '69']
网友评论