I can make a directory using a formatted string as the path. This works:
directory = r'\{ticker}\options\{exp_date}\{cp}'.format(ticker=ticker, exp_date=exp_date, cp=cp)
check_path_exists(directory)
def check_path_exists(directory):
if not os.path.exists(r'C:\ticker_data'+directory):
os.makedirs(r'C:\ticker_data'+directory)
But when I then try to export my dataframe to a csv it returns an error
df.to_csv(r'C:\{ticker}\options\{exp_date}\{cp}\{cp}.csv'.format(ticker=ticker, exp_date=exp_date, cp=cp))
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\MIK\\options\\2021-02-19\\calls\\calls.csv'
It is adding double slashes and I'm not sure why. I even manually created the csv file to make sure the entire path existed.