title: Using chardet to detect encoding
body: <p>I have already get the encoding of the file, but there is still error in encoding. I have no idea how to solve this problem. Could any one please help me?</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import os
  import chardet
  os.chdir(r'C:\Users\DELL\Desktop\beijing_20140101-20141231\beijing_20140101-20141231\beijingall')
  file_chdir = os.getcwd()
  
  filecsv_list = []
  for root,dirs,files in os.walk(file_chdir):
      for file in files:
          if os.path.splitext(file)[1] == '.csv':
              filecsv_list.append(file)
  
  data = pd.DataFrame()
  
  for csv in filecsv_list:
  
      csvc=csv.encode()
      encoding=chardet.detect(csvc).get("encoding")
      print(encoding)
  
      b=pd.read_csv(csv,encoding=encoding,header=None,sep=',',engine='python')
  </code></pre>
  
  <p><strong>Error:</strong> UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 15: ordinal not in range(128)</p>
  
  <p><strong>Error in detail:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/NxQff.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NxQff.png" alt="Error"></a></p>
  
  <p>I have got it done. I did not notice that it could be a problem with <strong>one of the files</strong>. The real problem is that one of the files is garbled. Delete this file and tried encoding='utf8' help me solve this problem.</p>