im looking for a way to add in a column called q17 and/or q20 if they do not already exist in a csv.
I have around 40 csvs, and i want a scrip that will search each one seeing if it has the columns q17 & q20. If it does not, the script will add in the missing column(s) and leave all the row values blank
import pandas as pd
from os import listdir
from os.path import isfile, join
onlyfiles = [f for f in listdir('.') if isfile(join('.', f))]
print(onlyfiles)
#add q17 and q20 if missing from csv sheet
df = onlyfiles
if ['q17'] not in df:
df['q17'] = ''
the script below returns the error "‘list’ objecet has no atribute columns" and im not sure why