title: how to create a function using python with dataframe to drop NaN values on a dynamic column name?
body: <p>i want to create function to drop NaN values but i need this function to be dynamic means that the end user can select the required column name and not being pre selected column.</p>
  <p>Header names:</p>
  <pre><code>['event_type', 'date', 'event_city','event_mouhafaza', 'number_person', 'groups']
  </code></pre>
  <h1>this is the function :</h1>
  <pre><code>def drop_nan(self,df):
          df.dropna(subset = [&quot;number_person&quot;], inplace=True)
  </code></pre>
  <p>i need to allow the user to change the <strong>number_person</strong> header's name into  one of the above list item.</p>
  <p>the code below show how i display the list of headers  with check-boxes in order to allow the user to check what he want.</p>
  <p>system crash and display the below error:</p>
  <blockquote>
  <pre><code>self.drop_nan_value.clicked.connect(lambda: self.drop_nan(self.df,self.colname)) AttributeError: 'Widget' object
  </code></pre>
  <p>has no attribute 'colname'</p>
  </blockquote>
  <p><a href="https://i.stack.imgur.com/8PuxN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8PuxN.png" alt="enter image description here" /></a></p>
  <h1>code:</h1>
  <pre><code>import pandas as pd
  
  from PandasModel import PandasModel
  
  import seaborn as sns
  import cufflinks as cf
  import plotly
  import plotly.offline as py
  import plotly.express as px 
  import plotly.graph_objs as go
  from plotly.offline.offline import iplot
  cf.go_offline()
  cf.set_config_file(offline=False, world_readable=True)
  
  
  class Widget(QtWidgets.QWidget):
      def __init__(self, parent=None):
          QtWidgets.QWidget.__init__(self, parent=None)
          self.gridLayout_3 = QtWidgets.QGridLayout(self)
          self.gridLayout_3.setObjectName(&quot;gridLayout_3&quot;)
         
          self.gridLayout_2 = QtWidgets.QGridLayout()
          self.gridLayout_2.setObjectName(&quot;gridLayout_2&quot;)
         
          self.gridLayout = QtWidgets.QGridLayout()
          self.gridLayout.setObjectName(&quot;gridLayout&quot;)
          
          self.pathLE = QtWidgets.QLineEdit(self)
          self.gridLayout_2.addWidget(self.pathLE, 0, 1, 1, 1)
          
  
          
          self.loadBtn = QtWidgets.QPushButton(&quot;Select File&quot;, self)
          self.loadBtn.clicked.connect(self.loadFile)
          self.gridLayout_2.addWidget(self.loadBtn, 0, 0, 1, 1)
          self.gridLayout_3.addLayout(self.gridLayout_2, 0, 0, 1, 4)
  
         
          self.displayHeader = QtWidgets.QPushButton(&quot;Display header&quot;, self)
          self.displayHeader.clicked.connect(lambda: self.print_df_header(self.df))
          self.gridLayout.addWidget(self.displayHeader, 2, 0, 1, 1)
          
          self.displayDF_checked_header = QtWidgets.QPushButton(&quot;Print checked item&quot;, self)
          self.displayDF_checked_header.clicked.connect(lambda: self.setItems(self.df))
          self.gridLayout.addWidget(self.displayDF_checked_header, 5, 0, 1, 1)
  
          self.drop_nan_value = QtWidgets.QPushButton(&quot;drop  NaN Values&quot;, self)
          self.drop_nan_value.clicked.connect(lambda: self.drop_nan(self.df,self.colname))
          self.gridLayout.addWidget(self.drop_nan_value, 4, 0, 1, 1)
          self.gridLayout_2.addLayout(self.gridLayout, 0, 2, 1, 1)   
  
          
          self.header_list = QtWidgets.QListWidget(self)
          self.header_list.setObjectName(&quot;listWidget&quot;)
          self.header_list.itemSelectionChanged.connect(self.selectionChanged)
          self.gridLayout_3.addWidget(self.header_list, 1, 2, 1, 1)
     
  
          self.pandasTv = QtWidgets.QTableView(self)
          self.verticalLayout.addWidget(self.pandasTv)
  
          self.pandasTv.setSortingEnabled(True)
  
  
       def loadFile(self):
          fileName, _ = QtWidgets.QFileDialog.getOpenFileName(self, &quot;Open File&quot;, &quot;&quot;, &quot;CSV Files (*.csv)&quot;);
          self.pathLE.setText(fileName)
          df = pd.read_csv(fileName)
          model = PandasModel(df)
          self.pandasTv.setModel(model)
          self.df = df
  
       def print_df_header(self,df):
          savelist = list(self.df)
          for item in savelist:
              qitem = QtWidgets.QListWidgetItem ( ) 
              qitem.setText ( item ) 
              qitem.setCheckState ( QtCore.Qt.Unchecked ) 
              self.header_list.addItem ( qitem )
          print(savelist)
  
       def selectionChanged(self):
       checked = []
       for row in range(self.header_list.count()):
          item = self.header_list.item(row)
          if item.checkState():
              checked.append(item)
       print(&quot;Checked items: &quot;, &quot;, &quot;.join(i.text() for i in checked))
  
       def drop_nan(self,df,colname):
          df.dropna(subset = [colname], inplace=True)
  
  
  if __name__ == &quot;__main__&quot;:
      import sys
      app = QtWidgets.QApplication(sys.argv)
      w = Widget()
      w.show()
      sys.exit(app.exec_())  
  </code></pre>