In particular, you can use the function pd.read_csv() with the URL as the first argument and the separator sep as the second argument. If you just wanted to load a file from the web into a DataFrame without first saving it locally, you can do that easily using pandas. You have just imported a file from the web, saved it locally and loaded it into a DataFrame. Opening and reading flat files from the web # Read file into a DataFrame and print its headĭf = pd.read_csv('winequality-red.csv', sep=' ')įixed acidity volatile acidity citric acid residual sugar chlorides \įree sulfur dioxide total sulfur dioxide density pH sulphates \ Use the function urlretrieve() to save the file locally as 'winequality-red.csv'.Įxecute the remaining code to load 'winequality-red.csv' in a pandas DataFrame and to print its head to the shell. Import the function urlretrieve from the subpackage urllib.request.Īssign the URL of the file to the variable url. The flat file contains tabular data of physiochemical properties of red wine, such as pH, alcohol content and citric acid content, along with wine quality rating.Īfter you import it, you'll check your working directory to confirm that it is there and then you'll load it into a pandas DataFrame. You are about to import your first file from the web! The flat file you will import will be 'winequality-red.csv' from the University of California, Irvine's Machine Learning repository. Importing flat files from the web: your turn! In : urlretrieve(url, 'winequality-white.csv') In : from urllib.request import urlretrieve
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |