我正试图使用pd.read_excel将一个包含多个工作表的excel文件导入到python中。我可以预先定义文件路径和excel文件名吗?这将使为具有不同文件路径和excel文件名的不同数据集运行脚本变得更容易。我尝试过这样的东西,但没有成功:
#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')
提前感谢!
试试这个
#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 (file_path + raw_data, sheet_name='copied and pasted excel sheet name here')