This question does not link with any question and does not have any answer to the problem
I need help to add new column in index (0) and field names to all csv files in directories and sub-directories. I have csv files like this
apple chocolate smoothies
orange dark cocoa ice-coffee
grapes brownies hot-choco
banana oreo ice-cream
I want my output csv files to be like this
Key A C S
Record_01 apple chocolate smoothies
Record_02 orange dark cocoa ice-coffee
Record_03 grapes brownies hot-choco
Record_04 banana oreo ice-cream
Firstly, I am trying to write the same Record column to all csv files in folder and nested folders.
Secondly, I am trying to write the same Field name to all csvfiles in folder and nested folders
I have tried this code
key = []
for row, Record in enumerate(key):print('Record_{}'.format(row, Record))row.append(row[0])key.appen(row)for roots, dirs, files in os.walk('path'):for csvfiles in files:if os.path.splitext(csvfiles)[0] == '.csv':with open(f'{csvfiles}', 'r') as csvinput:with open(f'{csvfiles}', 'w') as csvoutput:writer = csv.writer(csvoutput, delimiter=',')writer.writerow[key]
I have basically no idea how to add Record_{} by automatically to all csv files. please help me. Thank you for any answers.