Fix titanic data download function
parent
2f777d7f3f
commit
517a2f18be
|
@ -2528,22 +2528,21 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from pathlib import Path\n",
|
||||
"import pandas as pd\n",
|
||||
"import tarfile\n",
|
||||
"import urllib.request\n",
|
||||
"\n",
|
||||
"def load_titanic_data():\n",
|
||||
" titanic_path = Path() / \"datasets\" / \"titanic\"\n",
|
||||
" titanic_path.mkdir(parents=True, exist_ok=True)\n",
|
||||
" filenames = (\"train.csv\", \"test.csv\")\n",
|
||||
" for filename in filenames:\n",
|
||||
" filepath = titanic_path / filename\n",
|
||||
" if filepath.is_file():\n",
|
||||
" continue\n",
|
||||
" data_root = \"https://github.com/ageron/data/raw/main/\"\n",
|
||||
" url = data_root + \"titanic/\" + filename\n",
|
||||
" print(\"Downloading\", filename)\n",
|
||||
" urllib.request.urlretrieve(url, filepath)\n",
|
||||
" return [pd.read_csv(titanic_path / filename) for filename in filenames]"
|
||||
" tarball_path = Path(\"datasets/titanic.tgz\")\n",
|
||||
" if not tarball_path.is_file():\n",
|
||||
" Path(\"datasets\").mkdir(parents=True, exist_ok=True)\n",
|
||||
" url = \"https://github.com/ageron/data/raw/main/titanic.tgz\"\n",
|
||||
" urllib.request.urlretrieve(url, tarball_path)\n",
|
||||
" with tarfile.open(tarball_path) as titanic_tarball:\n",
|
||||
" titanic_tarball.extractall(path=\"datasets\")\n",
|
||||
" return [pd.read_csv(Path(\"datasets/titanic\") / filename)\n",
|
||||
" for filename in (\"train.csv\", \"test.csv\")]"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue