質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

860閲覧

書籍「Pythonで始める機会学習」の第4章のプログラムについて

zundokokiyoshi

総合スコア18

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2019/01/01 21:55

Pythonで始める機会学習の第4章の下記のサンプルコードを実行したのですが

%matplotlib inline from preamble import *
import os # The file has no headers naming the columns, so we pass header=None # and provide the column names explicitly in "names" adult_path = os.path.join(mglearn.datasets.DATA_PATH, "adult.data") data = pd.read_csv( adult_path, header=None, index_col=False, names=['age', 'workclass', 'fnlwgt', 'education', 'education-num', 'marital-status', 'occupation', 'relationship', 'race', 'gender', 'capital-gain', 'capital-loss', 'hours-per-week', 'native-country', 'income']) # For illustration purposes, we only select some of the columns data = data[['age', 'workclass', 'education', 'gender', 'hours-per-week', 'occupation', 'income']] # IPython.display allows nice output formatting within the Jupyter notebook display(data.head()) Initializing from file failed

以下のようなエラーがでてしまいます。このような場合はどうすればエラーを解決できるでしょうか??

--------------------------------------------------------------------------- OSError Traceback (most recent call last) <ipython-input-2-2df2b5e3d716> in <module> 8 'marital-status', 'occupation', 'relationship', 'race', 'gender', 9 'capital-gain', 'capital-loss', 'hours-per-week', 'native-country', ---> 10 'income']) 11 # For illustration purposes, we only select some of the columns 12 data = data[['age', 'workclass', 'education', 'gender', 'hours-per-week', ~\Anaconda3\lib\site-packages\pandas\io\parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, doublequote, delim_whitespace, low_memory, memory_map, float_precision) 676 skip_blank_lines=skip_blank_lines) 677 --> 678 return _read(filepath_or_buffer, kwds) 679 680 parser_f.__name__ = name ~\Anaconda3\lib\site-packages\pandas\io\parsers.py in _read(filepath_or_buffer, kwds) 438 439 # Create the parser. --> 440 parser = TextFileReader(filepath_or_buffer, **kwds) 441 442 if chunksize or iterator: ~\Anaconda3\lib\site-packages\pandas\io\parsers.py in __init__(self, f, engine, **kwds) 785 self.options['has_index_names'] = kwds['has_index_names'] 786 --> 787 self._make_engine(self.engine) 788 789 def close(self): ~\Anaconda3\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine) 1012 def _make_engine(self, engine='c'): 1013 if engine == 'c': -> 1014 self._engine = CParserWrapper(self.f, **self.options) 1015 else: 1016 if engine == 'python': ~\Anaconda3\lib\site-packages\pandas\io\parsers.py in __init__(self, src, **kwds) 1706 kwds['usecols'] = self.usecols 1707 -> 1708 self._reader = parsers.TextReader(src, **kwds) 1709 1710 passed_names = self.names is None pandas\_libs\parsers.pyx in pandas._libs.parsers.TextReader.__cinit__() pandas\_libs\parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source() OSError: Initializing from file failed

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

Python3.6のpandasで「Initializing from file failed」が起きた場合の対策によると、日本語(全角)を含むパスにファイルを配置していると提示エラーが発生するようです。半角のみで構成されたパスに配置してみてください。

投稿2019/01/01 22:17

can110

総合スコア38266

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

zundokokiyoshi

2019/01/01 22:51

半角のみのパス名にしたところう解決いたしました。 分かりやすいように日本語のファイル名に変更していたので原因でした。早速なご回答ありがとうございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問