I'm trying to import an excel file that has multiple sheets to python by using pd.read_excel. Can I define the file path and the excel file names beforehand? This will make it easier to run the script for the different dataset which has different file paths and excel file names. I tried something like this but didn't work:
#Define file path
file_path ="copied and pasted actual file path here"
#Define raw data excel sheet name
raw_data="copied and paste excel file name here"
#import excel
import pandas as pd
PL_raw_data = pd.read_excel (r'"file_path"/"raw_data".xlsx',sheet_name='copied and pasted excel sheet name here')
Thanks in advance!
how to use a variablequestion. Some complexity may arise due to the way you use the path. But, storing it in a variable vs not storing it in a variable shouldn't make a difference. Your problem lies in the way you're pass the string. Ther-literalmakes it so that everything is raw (and is so the quotes are kept in the string). You want to concatenate strings, or better usef-stringselsewhere and simply reference the variable.