Skip to content Skip to sidebar Skip to footer

Invalid Argument In Pd.read_excel

f=[] for root, dirs, files in os.walk(os.path.abspath(r'F:\Mathnasium Project\Downloaded files')): for file in files: f.append(os.path.join('r'+'''+root, file+''')) f

Solution 1:

It looks like something is wrong here: f.append(os.path.join("r"+'"'+root, file+'"'))

Try to print all values of 'f' and check whether it is a valid string or not to be passed to read_excel. like new_file=pd.read_excel(r"C:\Users\a\b\c\Raw Data\CO\acb.xls")

Solution 2:

It looks like you are trying to build a raw string to deal with backslashes in os.path.join("r"+'"'+root, file+'"'), but it doesn't work that way. The "r" is used when writing string literals like r"F:\Mathnasium Project\Downloaded files" in source files so that python's conversion of the text into a python string is not tripped up by the backslashes.

Once its a python string, there is no raw/not-raw variant. Any escaping is complete. All you really did was create a string

'r"F:\\Mathnasium Project\\Downloaded files\\Abdelrahman Mahmoud LP  05_11_2020.xlsx"'

and a windows path can't literally start with the characters 'r', '"', 'F', ':'. Instead, just join the already properly contructed strings from walk.

f=[]
for root, dirs, files in os.walk(os.path.abspath(r"F:\Mathnasium Project\Downloaded files")):
    for file in files:
        f.append(os.path.join(root, file))

Post a Comment for "Invalid Argument In Pd.read_excel"