title: Why am I getting permission denied? Python Pandas
body: <p>I am trying to write csv files to a sub-directory based on the name of the files in a different sub-directory. (from TimeSeries to Country Stats)</p>
  
  <pre><code>source1 = "C:/Users/USER/PycharmProjects/Corona Stats/TimeSeries"
  path1 = "C:/Users/USER/PycharmProjects/Corona Stats/Country Series/"
  
  
  def country_csv():
      # loop through absolute paths of each file in source
      for filename in os.listdir(source1):
          filepath = os.path.join(source1, filename)
          if not os.path.isfile(filepath):
              continue
          df = pd.read_csv(filepath)
          df = df.groupby(['Country']).sum()
          df = df.reset_index()
          df.to_csv(os.path.join(filepath, path1))
  
  
  country_csv()
  </code></pre>
  
  <p>Gives me"</p>
  
  <pre><code>PermissionError: [Errno 13] Permission denied: 'C:/Users/USER/PycharmProjects/Corona Stats/Country Series/'
  </code></pre>
  
  <p>I had written them to TimeSeries by accident by doing:</p>
  
  <pre><code>df.to_csv(os.path.join(path1, filepath))
  </code></pre>
  
  <p>Doing just:</p>
  
  <pre><code>df.to_csv(path1)
  </code></pre>
  
  <p>Yields the same permission denied error.</p>