title: Python Pandas QTableView How to delete selected rows and refresh qtableview
body: <p>I have a QTableView based on QAbstractTableModel, the data comes from a pandas. Now i would like to select multiple rows and refresh the tableview. So far I have this coding after delete button has been clicked:</p>
  <p><a href="https://i.stack.imgur.com/ATdm0.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ATdm0.jpg" alt="enter image description here" /></a></p>
  <p>This is the complete code:</p>
  <pre><code>from modules.scraper import scrape
  from PyQt5 import uic
  from PyQt5 import uic, QtGui, QtCore
  from PyQt5.QtWidgets import *
  from PyQt5.QtCore import Qt
  from PyQt5.QtGui import QStandardItemModel
  import sys
  import Email
  
  class TableModel(QtCore.QAbstractTableModel):
  
  def __init__(self, data):
      super(TableModel, self).__init__()
      self._data = data
  
  def data(self, index, role):
      if role == Qt.DisplayRole:
          value = self._data.iloc[index.row(), index.column()]
          return str(value)
  
  def rowCount(self, index):
      return self._data.shape[0]
  
  def columnCount(self, index):
      return self._data.shape[1]
  
  def headerData(self, section, orientation, role):
      # section is the index of the column/row.
      if role == Qt.DisplayRole:
          if orientation == Qt.Horizontal:
              return str(self._data.columns[section])
  
          if orientation == Qt.Vertical:
              return str(self._data.index[section])
          
  class MainWindow(QMainWindow):
      def __init__(self):
          super(MainWindow, self).__init__()
          uic.loadUi(r&quot;BusinessFinder.ui&quot;, self)
          self.pushButtonLoadLeads.clicked.connect(lambda: 
          [self.load_leads(self.lineEditLocation.text(), 
      self.lineEditBusiness.text())])
      # self.pushButtonScrapeMail.clicked.connect(self.scrape_mails)
      self.pushButtonClose.clicked.connect(self.close)
      self.pushButtonDelete.clicked.connect(self.delete)
      
  def load_leads(self, places, query):
      self.data = scrape(query, places)
      self.model = TableModel(self.data)
  
      # for index, row in data.iterrows():
      #     url_to_scrape =(row['Website']).strip()
      #     email = Email.get_email(url_to_scrape)
      #     row[4] = email
  
      self.tableView.setModel(self.model)
      
  def delete(self):
      if self.tableView.selectionModel().hasSelection():
          for index in self.tableView.selectionModel().selectedRows() :
              self.model.beginRemoveRows(QModelIndex(),
                                             index.row(),index.row())                    
              self.model.removeRow(index.row())
              self.model.endRemoveRows()
  
  
  if __name__ == &quot;__main__&quot;:
      app = QApplication([])
      window = MainWindow()
      window.show()
      sys.exit(app.exec())   
  </code></pre>
  <p>In the delete def it always deletes the last rows, no matter what i select</p>