import csv def read_csvList(path="./datasets/test.csv")->list: """return data format [[],[]]""" with open(file=path,mode="r")as f: df=csv.reader(f,dialect='excel',delimiter=',', quotechar='|') sets=[i for i in df ] print(sets[:2]) return sets def read_csvDict(path=None)->dict: with open(file="./datasets/breast_a.csv",mode="r") as f: df=csv.DictReader(f) data_set= dict([(i['id'],[i["x0"],i["x1"]]) for i in df]) return data_set def write_csv(path='./datasets/test.csv',data=None): """ data format=[[],[]] or [(),()]""" with open (file=path,mode='w',newline='')as f: wt=csv.writer(f) wt.writerows(data) if __name__ == '__main__': write_csv(data=[["张三",99],["李四",88]])