import os outname = 'name.csv' outdir = './dir' if not os.path.exists(outdir): os.mkdir(outdir) fullname = os.path.join(outdir, outname) df.to_csv(fullname)