title: Scraping data from a table and storing it in csv file
body: <p>I would want to scrap the data from this website and store it in csv file in this manner.</p>
  
  <p><a href="https://i.stack.imgur.com/eWjPZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eWjPZ.png" alt="enter image description here"></a></p>
  
  <p>But when I try to scrap the data it is not stored in exact format. All the data is stored in the 1st column itself. I have no idea how to approach this problem.</p>
  
  <p>Link : <a href="https://pce.ac.in/students/bachelors-students/" rel="nofollow noreferrer">https://pce.ac.in/students/bachelors-students/</a></p>
  
  <p>Code:</p>
  
  <pre><code>import csv  # file operations
  from bs4 import BeautifulSoup as soup  # lib for pulling data from html/xmlsites
  from urllib.request import urlopen as uReq  # lib for sending and rec info over http
  Url = 'https://pce.ac.in/students/bachelors-students/'
  pageHtml = uReq(Url)
  soup = soup(pageHtml,"html.parser") #parse the html
  table = soup.find_all("table", { "class" : "tablepress tablepress-id-10 tablepress-responsive-phone" })
  f = csv.writer(open('BEPillaiDepart.csv', 'w'))
  f.writerow(['Choice Code', 'Course Name', 'Year of Establishment','Sanctioned Strength'])  # headers
  for x in table:
      data=""
      table_body = x.find('tbody') #find tbody tag
      rows = table_body.find_all('tr') #find all tr tag
      for tr in rows:
          cols = tr.find_all('td') #find all td tags
          for td in cols:
              data=data+ "\n"+ td.text.strip()
              f.writerow([data])
  #print(data)
  </code></pre>