title: How can I webscrape a Wikipedia table with lists of data instead of rows?
body: <p>I am trying to get data from the Localities table located on the Wikipedia <a href="https://en.wikipedia.org/wiki/Districts_of_Warsaw" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Districts_of_Warsaw</a> page.</p>
  <p>I would like to collect this data and put it into a dataframe with two columns [&quot;Districts&quot;] and [&quot;Neighbourhoods&quot;].</p>
  <p>My code so far looks like this:</p>
  <pre><code>url = &quot;https://en.wikipedia.org/wiki/Districts_of_Warsaw&quot;
  page = urllib.request.urlopen(url)
  soup = BeautifulSoup(page, &quot;html&quot;)
  
  table = soup.find_all('table')[2]
  
  A=[]
  B=[]
  
  for row in table.findAll('tr'):
      cells=row.findAll('td')
      if len(cells)==2:
          A.append(cells[0].find(text=True))
          B.append(cells[1].find(text=True))
  
  df=pd.DataFrame(A,columns=['Neighbourhood'])
  df['District']=B
  print(df)
  </code></pre>
  <p>This gives the following dataframe:</p>
  <p><a href="https://i.stack.imgur.com/XgtVj.png" rel="nofollow noreferrer">Dataframe</a></p>
  <p>Certainly, scraping the Neighbourhood column is not right since they are contained in lists, but I don't know how it should be done so will be glad for any tips.</p>
  <p>In addition to it, I will appreciate any hints why scraping gives me only 10 districts instead of 18.</p>