你可以做这样的事情。
from collections import defaultdict
from pathlib import Path
import pandas as df
my_dir_path = "/parh/to/folder"
results = defaultdict(list)
for file in Path(my_dir_path).iterdir():
with open(file, "r") as file_open:
results["file_name"].append(file.name)
results["text"].append(file_open.read())
df = pd.DataFrame(results)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6189 次 |
| 最近记录: |