title: Python CSV Filter with Pandas
body: <p>I've been sitting on this problem for a few days now.
  I have a CSV with about 400 columns and I need to filter them by country. Unfortunately I don't have a header for the CSV so I added one myself. Now I want to filter by it but it always writes me only the first line and does not filter it properly. Do you have any ideas?</p>
  <p>Thanks
  <a href="https://i.stack.imgur.com/SPZeX.png" rel="nofollow noreferrer">Picture of New CSV with problems</a>
  <a href="https://i.stack.imgur.com/CeUNT.png" rel="nofollow noreferrer">Picture of CSV</a></p>
  <p>Code:</p>
  <pre><code>import pandas as pd
  import csv
  
  
  
  def checkcsv(pfadfile1, pfadfile2, Land):
    with open(pfadfile1, 'r') as f_in:
      with open(pfadfile2, 'w') as f_outfile:
          writer = csv.writer(f_outfile, delimiter=&quot;|&quot;)
          writer.writerow([&quot;1&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot;, &quot;6&quot;, &quot;7&quot;, &quot;8&quot;, &quot;9&quot;, &quot;10&quot;, &quot;Location&quot;, &quot;12&quot;, &quot;13&quot;, &quot;14&quot;, &quot;15&quot;])
  
          f_out = csv.writer(f_outfile, escapechar='|', quoting=csv.QUOTE_NONE)
  
          for line in f_in:
              line = line.strip()
              row = []
              if Land in line:
                  row.append(line)
                  f_out.writerow(row)
    def load_source(Land):
      with open(&quot;SILNOVA_DE.csv&quot;, &quot;r&quot;) as f:
        with open(&quot;SILNOVA_DE_FINAL.csv&quot;, &quot;w&quot;) as isfile:
          df = pd.read_csv(&quot;SILNOVA_DE.csv&quot;, sep='|', encoding='ISO-8859-1')
          df = df[(df[&quot;Location&quot;] == Land)]
  
          #df.to_csv(pfadfile2, index=False, sep='|')
  
          writer = csv.writer(isfile, delimiter='|', lineterminator='\n')
          writer.writerow(df)
  
          print(df)
  
  
  
  
  def main():
  # show()
  checkcsv(&quot;Beispiel.csv&quot;, &quot;SILNOVA_DE.csv&quot;, &quot;AT&quot;)
  ReadWriteconfig_file(&quot;SILNOVA_DE.csv&quot;)
  load_source(&quot;AT&quot;)
  
  
  main()
  </code></pre>