1
import pandas as pd
df = pd.read_excel(r'C:\Users\name\Documents\Data\/' + file+ '.xlsx')

FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\name\Documents\/file.xlsx'

I try this is Documents path and it work, but when I adding one more file folder(Data) to it, python show me that he didn't go in to the Data file folder.

Gun hanwei
  • 93
  • 1
  • 7
  • Does this answer your question? [Reading an Excel file in python using pandas](https://stackoverflow.com/questions/17063458/reading-an-excel-file-in-python-using-pandas) – Jay Kakadiya Oct 21 '20 at 03:43

2 Answers2

0

You don't need that last / before file

Cal Lee
  • 50
  • 6
0

below code would help you

file = 'sample'
df = pd.read_excel(r'C:\\Users\\name\\Documents\\Data\\' + file+ '.xlsx')

or

\ backslash sometimes behave as escape sequences. To avoid that situation

df = pd.read_excel(r'C:/Users/name/Documents/Data/' + file+ '.xlsx')
Subbu VidyaSekar
  • 2,503
  • 3
  • 21
  • 39