头文件
import csv
import pandas as pd
建一个csv文件
csv_path = result_path + file_name + '.csv'
dataDic={'video_name':[],'imgname':[]}
df = pd.DataFrame(dataDic)
df.to_csv(csv_path)
写入每列对应的数据
dataDic={'video_name':[video_name],'imgname':[imgname]}
df = pd.DataFrame(dataDic)
df.to_csv(csv_path,mode='a',header=False)
df.to_csv(csv_path,mode='w',header=False)
读取csv文件内的数据
方法1:
with open(csv_path, "r") as f:
reader = csv.DictReader(f)
for row in reader:
print(row['img_name'])
f.close()
方法2:
with open(csv_path, "r") as f:
reader = csv.reader(f)
for row in reader:
print(row[0])
f.close()