'Errno 22 Invalid argument when trying to export dataframe to excel

I'm trying to export my dataframe to excel (in Windows). My code looks like this:

import os
import pandas as pd

clients_file = pd.read_excel("count.xlsx", engine="openpyxl", header=0)
clients_file.to_excel(os.path.join("path", "backup", "weekly", "12345", "12345" + "_" + pd.datetime.today().strftime('%Y-%m-%d-%H:%M:%S')) + ".xlsx", index=False, sheet_name="report") 

My problem is that I get this error:

OSError: [Errno 22] Invalid argument: 'path\\backup\\weekly\\12345\\12345_2022-03-03-12:10:56.xlsx'

and I don't know really why. I know that I can use "+" to join strings, but path.join is nicer to read. Any ideas ? Cheers!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source