This is the beginning of my code that takes a dataset and plots it using matplotlib. However, I want to create a while loop that prompts the user to provide the correct path or directory to the file (e.g. /Users/Hello/Desktop/file.txt).
While the user does not inputs a correct path, the loop should keep prompting for a directory.
If there is indeed a file in that path, it should store this input in the variable path, which is later used to display the data.
If there is no file, it should ask it again.
It seems that my while loop is stuck at the first print statement..
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import itertools
import os
# This is the correct directory: os.path.isfile('/Users/Hello/Desktop/file.txt')
"""
Prompt the user for the right directory to the file.
If the file is not there, ask again.
If the path is correct, store it in the variable Path.
"""
correct = os.path.isfile(directory)
directory = input("Please provide the correct directory to the dataset ")
while os.path.isfile == False:
if os.path.isfile(Directory) != True:
directory = ath
print('Thank you')
elif os.path.isfile(Directory) == True:
print("This directory does not exist, please try again.")
#this variable inserts the users input and displays the data in the file
dframe = pd.read_table(path, delim_whitespace=True, names=('X','Y'),
dtype={'X': np.float64, 'Y':np.float64})
dframe.head(10) # show the first 10 rows of the data