Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
paths
#1
Hi everyone,

I am having a lot of trouble with setting up paths in my code to pull data from. My most recent problem is with this code below

import os
import tarfile
from six.moves import urllib

DOWNLOAD_ROOT = "https://raw.githubusercontent.com/ageron/handson-ml/master/"
HOUSING_PATH = os.path.join("datasets", "housing")
HOUSING_URL = DOWNLOAD_ROOT + "datasets/housing/housing.tgz"

def fetch_housing_data(housing_url=HOUSING_URL, housing_path=HOUSING_PATH):
    if not os.path.isdir(housing_path):
        os.makedirs(housing_path)
    tgz_path = os.path.join(housing_path, "housing.tgz")
    urllib.request.urlretrieve(housing_url, tgz_path)
    housing_tgz = tarfile.open(tgz_path)
    housing_tgz.extractall(path=housing_path)
    housing_tgz.close()

import pandas as pd

def load_housing_data(housing_path=HOUSING_PATH):
    csv_path = os.path.join(housing_path, "housing.csv")
    return pd.read_csv(csv_path)
I am running the code in spyder and then doing the below code in jupter notebook to try view it.

housing = load_housing_data()
housing.head()
I get the below error

FileNotFoundError: File b'datasets\\housing\\housing.csv' does not exist

Can anyone help me I want to start modelling on the data but am getting stuck :(
Reply


Messages In This Thread
paths - by Scott - May-15-2018, 08:34 AM
RE: paths - by buran - May-15-2018, 08:39 AM
RE: paths - by Scott - May-15-2018, 08:51 AM
RE: paths - by buran - May-15-2018, 08:55 AM
RE: paths - by Scott - May-15-2018, 09:02 AM
RE: paths - by buran - May-15-2018, 09:52 AM
RE: paths - by Scott - May-15-2018, 10:01 AM
RE: paths - by buran - May-15-2018, 10:02 AM
RE: paths - by Scott - May-15-2018, 10:04 AM
RE: paths - by buran - May-15-2018, 10:08 AM
RE: paths - by buran - May-15-2018, 10:09 AM
RE: paths - by Scott - May-15-2018, 10:11 AM
RE: paths - by buran - May-15-2018, 10:14 AM
RE: paths - by Scott - May-16-2018, 06:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Retrieving last 20 file paths from directory dyerlee91 3 2,056 Sep-24-2021, 12:55 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020