title: How to filter a dataframe by user inputs in Django filter?
body: <p>I want to filter a dataframe that is pivoted from a model.</p>
  
  <p>Model.py is:</p>
  
  <pre><code>class MTD(models.Model):
      RGN = models.CharField(max_length = 60, db_column = 'RGN')
      Channel = models.CharField(max_length = 60, db_column = 'Channel')
      Vertical = models.CharField(max_length = 60, db_column = 'Vertical')
      Brand = models.CharField(max_length = 60, db_column = 'Brand')
      Sales_Value = models.CharField(max_length = 60, db_column = 'Sales Value')
      Month = models.CharField(max_length = 60, db_column = 'Month')
  
      City = models.CharField(max_length = 60, db_column = 'City')
  
      objects = models.Manager()
      pdobjects = DataFrameManager()
  
  
      def __str__(self):
              field_values = []
              for field in self._meta.get_fields():
                  field_values.append(str(getattr(self, field.name, '')))
              return ' '.join(field_values)
  </code></pre>
  
  <p>I am filtering only three columns from my model ('VERTICAL', 'CHANNEL', 'SALES VALUE') and I am converting this into a dataframe. From the derived dataframe I am not able to filter the data as requested by the user. I am posting the code which I have tried so far.</p>
  
  <p>Table.html</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en" dir="ltr"&gt;
    &lt;head&gt;
      {% load static %}
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;&lt;/title&gt;
    &lt;/head&gt;
    &lt;body class="hold-transition skin-blue sidebar-mini"&gt;
      &lt;h1&gt;Pandas dataframe from MyModel&lt;/h1&gt;
      &lt;form method="GET"&gt;
        {{ filter.form.as_p }}
        &lt;button type="submit"&gt;Search&lt;/button&gt;
      &lt;/form&gt;
  
      {{ filter|safe }}
      {{ Table|safe }}
  
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Filter.py</p>
  
  <pre><code>from dash.models import MTD
  import django_filters
  
  class UserFilter(django_filters.FilterSet):
      class Meta:
          model = MTD
          fields = ['Vertical', 'Channel', ]
  </code></pre>
  
  <p>Views.py</p>
  
  <pre><code>from dash.filter import UserFilter
  
  
  def salebycustomer(request):
      sbc = MTD.pdobjects.values('Vertical', 'Channel','Sales_Value')
      user_filter = UserFilter(request.GET, queryset=sbc)
      sbc_df = sbc.to_dataframe().reset_index(drop=True)#Trying to use filtered model for dataframe
      sbc_df['Sales_Value']=sbc_df['Sales_Value'].astype(float)
  
      sbc_df1 = pandas.pivot_table(sbc_df,values='Sales_Value', index='Vertical', columns='Channel',aggfunc='sum').rename_axis(None,axis=1).replace(numpy.nan,0)
      sbc_df1.reset_index(inplace=True)
  
      # sbc_df1.columns = [''.join(col).strip() for col in sbc_df1.columns.values]
  
      # sbc_df1=sbc_df1.T.to_dict().values()
      template = 'table.html'
  
  
      sbc_df2 = sbc_df1.to_html()
  
      context= {'filter': user_filter,'Table':sbc_df2}
  
      return render(request, template, context)
  </code></pre>
  
  <p>Plz help me to resolve this.
  <a href="https://i.stack.imgur.com/tZlLH.jpg" rel="nofollow noreferrer">Kindly refer this screenshot</a></p>
  
  <p>Thanks</p>