column headers in the first rowthe dictreader object would use : ''apples'and ' as the dictionary keys to avoid thisyou can supply the dictreader(function with second argument containing made-up header namesimport csv examplefile open('example csv'exampledictreader csv dictreader(examplefile['time''name''amount']for row in exampledictreaderprint(row['time']row['name']row['amount'] : apples : cherries : pears : oranges : apples : bananas : strawberries because example csv' first row doesn' have any text for the heading of each columnwe created our own'time''name'and 'amountdictwriter objects use dictionaries to create csv files import csv outputfile open('output csv'' 'newline=''outputdictwriter csv dictwriter(outputfile['name''pet''phone']outputdictwriter writeheader(outputdictwriter writerow({'name''alice''pet''cat''phone'' '} outputdictwriter writerow({'name''bob''phone'' - '} outputdictwriter writerow({'phone'' - ''name''carol''pet''dog'} outputfile close(if you want your file to contain header rowwrite that row by calling writeheader(otherwiseskip calling writeheader(to omit header row from the file you then write each row of the csv file with writerow(method callpassing dictionary that uses the headers as keys and contains the data to write to the file the output csv file this code creates looks like thisname,pet,phone alice,cat, - bob,, - carol,dog, - working with csv files and json data