擅长:python、mysql、java
<p>我想你需要<code>os.listdir()</code>:</p>
<pre><code>#Be careful this might give you a memory error if you
#don't have enough ram for all your files
#and make sure the folder contains only the files you want to read
import os
files = os.listdir('ethnicity_files/')
list_of_dfs = []
for file in files:
d = pickle.load(os.path.join('ethnicity_files/',file))
df = pd.concat({k:json_normalize(v, 'scores', ['best']) for k,v in d.items()})
df = df.reset_index(level=1, drop=True).rename_axis('names').reset_index()
list_of_dfs.append(df)
big_df = pd.concat(list_of_dfs, ignore_index=True)#ignore_index to reset index of big_df
big_df.head()
</code></pre>