前提・実現したいこと
SB Creative「作業が一瞬で片付く Python 自動化仕事術」第2章Excelの自動化 にて、指定したExcelファイルを取り込みたいです。当方Python初心者です。ご教授の程宜しくお願い致します。
発生している問題・エラーメッセージ
取り込むファイルのパスを認識できていないのか、変数dataに格納することができません。(一部、ユーザー名を置き換えています)
--------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_16056/3944496063.py in <module> ----> 1 data = pd.read_excel(path) ~\anaconda3\lib\site-packages\pandas\util\_decorators.py in wrapper(*args, **kwargs) 309 stacklevel=stacklevel, 310 ) --> 311 return func(*args, **kwargs) 312 313 return wrapper ~\anaconda3\lib\site-packages\pandas\io\excel\_base.py in read_excel(io, sheet_name, header, names, index_col, usecols, squeeze, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, parse_dates, date_parser, thousands, comment, skipfooter, convert_float, mangle_dupe_cols, storage_options) 362 if not isinstance(io, ExcelFile): 363 should_close = True --> 364 io = ExcelFile(io, storage_options=storage_options, engine=engine) 365 elif engine and engine != io.engine: 366 raise ValueError( ~\anaconda3\lib\site-packages\pandas\io\excel\_base.py in __init__(self, path_or_buffer, engine, storage_options) 1189 ext = "xls" 1190 else: -> 1191 ext = inspect_excel_format( 1192 content_or_path=path_or_buffer, storage_options=storage_options 1193 ) ~\anaconda3\lib\site-packages\pandas\io\excel\_base.py in inspect_excel_format(content_or_path, storage_options) 1068 content_or_path = BytesIO(content_or_path) 1069 -> 1070 with get_handle( 1071 content_or_path, "rb", storage_options=storage_options, is_text=False 1072 ) as handle: ~\anaconda3\lib\site-packages\pandas\io\common.py in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options) 709 else: 710 # Binary mode --> 711 handle = open(handle, ioargs.mode) 712 handles.append(handle) 713 FileNotFoundError: [Errno 2] No such file or directory: "C:'Users'ユーザー名'python_sample'練習用ファイル'chapter2'data.xlsx"
該当のソースコード
Python
1import pandas as pd 2path='C:\'Users\'ユーザー名\'python_sample\'練習用ファイル\'chapter2\'data.xlsx' 3data = pd.read_excel(path)
試したこと
シングルクォーテーションを¥'のように表記したり、ライブラリからファイルのアドレスをコピーしたり、色々試行錯誤しましたが、ダメでした。
補足情報(FW/ツールのバージョンなど)
ランチャーはJupyterLabを使用しています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/01/24 17:54 編集
2022/01/25 12:56