【发布时间】:2020-03-07 08:33:49
【问题描述】:
我正在努力学习熊猫。我通常使用以下方法导入 excel 表:
import pandas as pd
df = pd.read_excel (r'C:\Users\Comp\Documents\filename.xlsx')
但我希望让用户自己输入文件位置。 我尝试将文件位置作为输入并使用格式选项,但它并没有真正为我工作。这是我尝试过的:
print("Do you have another sheet for a new DF?")
ch = input("Press Y or N")
if ch =="Y":
df2 = pd.read_excel (r'{}'.format(input("copy and paste the location of the excel file here ")))
请告诉我如何完成这项任务。谢谢你:)
【问题讨论】: