I want to make the database as my all data is in the form of CSV. having 160 column and 15 rows. as the column are more so to write the name manually is very hard I want to do it like get the column names from csv file and store it in a variable I did this. My column name are now in a variable. but I'm not able to assign these value to database column.
def parseCSV(filePath):
# CVS Column Names
data = pd.read_csv(filePath)
column = data.columns
# Use Pandas to parse the CSV file
csvData = pd.read_csv(filePath,names=column, header=None)
# Loop through the Rows
# for i,row in csvData.iterrows():
# sql = "INSERT INTO addresses (first_name, last_name, address, street, state, zip) VALUES (%s, %s, %s, %s, %s, %s)"
# value = (row['first_name'],row['last_name'],row['address'],row['street'],row['state'],str(row['zip']))
# mycursor.execute(sql, value, if_exists='append')
# mydb.commit()
# print(i,row['first_name'],row['last_name'],row['address'],row['street'],row['state'],row['zip'])
I comment those line which is hard coded. I want this column name come from CSV not to be added manually.