import os
import pandas as pd
df_main = pd.DataFrame()
for file in os.listdir():
if file.endswith("Milan.csv"):
df_temp = pd.read_csv(file)
df_main = df_main.append(df_temp, ignore_index=True)
df_main.to_csv("output.csv", index=False)
from pathlib import Path
import pandas as pd
path = "/path/to/files/"
(pd
.concat(objs=(pd.read_csv(x) for x in Path(path).glob("*Milan.csv")), ignore_index=True)
.to_csv(path_or_buf=f"{path}output.csv", index=False)
)
2条答案
按热度按时间abithluo1#
3htmauhk2#
使用pathlib: