title: How to Read Data from CSV row by row and store in database
body: <p>I have a csv file with 20 records that need to stored in a table inside a database. I am trying to read every row line by line but not sure how to pass it to a function which would check the connection with database and store in it. I have created a separate <strong>config file</strong> for connection object for database.</p>
  <p>How should I read the csv line by line and <strong>pass every row data</strong> to <strong>function</strong> and store it and carry out the same operation for every other row of csv. My code is as follows:</p>
  <pre><code># This variable stores the insert query to store data in database
  query = &quot;&quot;&quot;INSERT INTO product(product_id, product_name, description, product_value) 
  values(%s, %s, %s, %s)&quot;&quot;&quot;
  
  def create_product():
  data = pd.read_csv('path/to/csv')
  df = pd.DataFrame(data)
  data_list = []
  
  # How to Write This part?
  # How will I pass an entire row in the function call and what to have in the argument like a 
  # List or something
  for row in df.iterrows():
      # print(row)
      input_data = &quot;,&quot;.join(row)
      insert_data = output_data_to_DB(query, input_data, connect_db) # Calling Function
      data_list.append(insert_data)
      print(data_list)
  
  # Called Function Here
  def output_data_to_DB(insert_query, output_list, conn):
  try:
      cur = conn.cursor()
      cur.execute(insert_query, output_list)
      print(&quot;row inserted with valueList : &quot;, output_list)
      output_list.commit()
      cur.close()
      return &quot;&quot;
  except Exception as e:
      connect_db.rollback()
      cur.close
  </code></pre>
  <p>I would appreciate any kind of help. I am not that familiar with python programs.</p>