擅长:python、mysql、java
<p>您可以使用<a href="https://docs.python.org/3/library/os.html#os.listdir" rel="nofollow noreferrer">os.listdir</a>或<a href="https://docs.python.org/3/library/glob.html" rel="nofollow noreferrer">glob</a>模块列出目录中的所有文件。在</p>
<p>与操作系统列表目录,您可以使用<a href="https://docs.python.org/3/library/fnmatch.html#fnmatch.fnmatch" rel="nofollow noreferrer">fnmatch</a>来过滤这样的文件(也可以使用regex)</p>
<pre><code>import fnmatch
import os
for file in os.listdir('my_directory'):
if fnmatch.fnmatch(file, '*.xlsx'):
pd.read_excel(open(file, 'rb'), sheetname = 'Sheet1')
""" Do your thing to file """
</code></pre>
<p>或者使用glob module(这是fnmatch+listdir的快捷方式),您可以这样做(或者使用regex):</p>
^{pr2}$