For Those Working Locally: File Paths
When you complete a project locally and then upload it to our platform, problems related to file paths can arise. Check out this video to see how try...except
blocks can help you deal with this issue (text follows):
When you're working locally, your dataset is usually in the same folder as your Jupyter notebook. But on the platform, datasets are stored in a separate folder. That means your file paths won't work, and when our reviewers run the project, there'll be errors.
Fortunately, you can use try...except
to make sure that the project runs both on your machine and on the platform.
Let's say this path works on your local machine:
df = pd.read_csv('read_estate_data_us.csv')
On TripleTen's platform, the path will need to be
/datasets/real_estate_data_us.csv
.
Let's wrap this in a try...except
block:
1try:2 df = pd.read_csv('real_estate_data_us.csv')3except:4 df = pd.read_csv('/datasets/real_estate_data_us.csv')
Python tries to execute the first line, and if the first path doesn't work, it tries the second path (instead of raising a FileNotFound
exception).
Now you can upload your .ipynb notebook file to our platform.