I am trying to learn Pandas. I usually import the excel sheet using :
import pandas as pd df = pd.read_excel (r'C:\\Users\\Comp\\Documents\\filename.xlsx')
But I was hoping to make the user input the file location on their own. I tried taking the file location as the input and using the format option but it didn't really work for me. Here is what I've tried :
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 ")))
Please let me know how I can achieve this task. Thank you :)
Here is some information what is going on: Remove u202a from Python string
You could do the following:
print("Do you have another sheet for a new DF?")
ch = input("Press y or n")
if ch =="y":
filePath = input("copy and paste the location of the excel file here ")
filePath = filePath.strip("u202a")
df2 = pd.read_excel (r'{}'.format(filePath))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.