Код: Выделить всё
import os
def save(df, filepath):
dir, filename = os.path.split(filepath)
os.makedirs(dir, exist_ok=True)
_, ext = os.path.splitext(filename)
match ext:
case ".pkl":
df.to_pickle(filepath)
case ".csv":
df.to_csv(filepath)
case _:
raise NotImplementedError(f"Saving as {ext}-files not implemented.")
Подробнее здесь: https://stackoverflow.com/questions/744 ... statements
Мобильная версия