admin管理员组

文章数量:1405192

I would like to try to work the dataset in Jupyter Notebook from the iPhone Carnets App, but I can’t search the correct path. If someone can help me.

The dataset I download from Kaggle. Are free files that I push into a folder. I try this code:

import pandas as pd

aguacates = pd.read_excel("⁨⁨⁨En mi       iPhone⁩ ▸ ⁨video141_python_pildorasInfor⁩ ▸     Aguacate producción.xlsx")
print(aguacates)

And also this other:

import pandas as pd

aguacates = pd.read_excel("⁨⁨⁨En mi iPhone⁩ \\video141_python_pildorasInfor⁩\\Aguacate producción.xlsx")
(aguacates)

The error is:

`FileNotFoundError                         Traceback (most recent call last)
Cell In[2], line 3
  1 import pandas as pd
----> 3 aguacates = pd.read_excel("⁨⁨En mi iPhone⁩\\⁨video141_python_pildorasInfor⁩\\Aguacate producción.xlsx")
  4 print(aguacates)

File /private/var/containers/Bundle/Application/D169301A-0DB7-4982-8FE3-9C6D0E0C17D8/Carnets.app/Library/lib/python3.11/site-packages/pandas/io/excel/_base.py:478, in read_excel(io, sheet_name, header, names, index_col, usecols, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, parse_dates, date_parser, date_format, thousands, decimal, comment, skipfooter, storage_options, dtype_backend)
476 if not isinstance(io, ExcelFile):
477     should_close = True
--> 478     io = ExcelFile(io, storage_options=storage_options, engine=engine)
479 elif engine and engine != io.engine:
480     raise ValueError(
481         "Engine should not be specified when passing "
482         "an ExcelFile - ExcelFile already has the engine set"
483     )

File /private/var/containers/Bundle/Application/D169301A-0DB7-4982-8FE3-9C6D0E0C17D8/Carnets.app/Library/lib/python3.11/site-packages/pandas/io/excel/_base.py:1496, in ExcelFile.__init__(self, path_or_buffer, engine, storage_options)
   1494     ext = "xls"
   1495 else:
-> 1496     ext = inspect_excel_format(
   1497         content_or_path=path_or_buffer, storage_options=storage_options
   1498     )
   1499     if ext is None:
   1500         raise ValueError(
   1501             "Excel file format cannot be determined, you must specify "
   1502             "an engine manually."
   1503         )

File /private/var/containers/Bundle/Application/D169301A-0DB7-4982-8FE3-9C6D0E0C17D8/Carnets.app/Library/lib/python3.11/site-packages/pandas/io/excel/_base.py:1371, in inspect_excel_format(content_or_path, storage_options)
   1368 if isinstance(content_or_path, bytes):
   1369     content_or_path = BytesIO(content_or_path)
-> 1371 with get_handle(
   1372     content_or_path, "rb", storage_options=storage_options, is_text=False
   1373 ) as handle:
   1374     stream = handle.handle
   1375     stream.seek(0)

File /private/var/containers/Bundle/Application/D169301A-0DB7-4982-8FE3-9C6D0E0C17D8/Carnets.app/Library/lib/python3.11/site-packages/pandas/io/common.py:868, in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
    859         handle = open(
    860             handle,
    861             ioargs.mode,
   (...)
    864             newline="",
    865         )
    866     else:
    867         # Binary mode
--> 868         handle = open(handle, ioargs.mode)
    869     handles.append(handle)
    871 # Convert BytesIO or file objects passed with an encoding

FileNotFoundError: [Errno 2] No such file or directory: '\u2068\u2068En mi iPhone\u2069\\\u2068video141_python_pildorasInfor\u2069\\Aguacate producción.xlsx'`

I would like to try to work the dataset in Jupyter Notebook from the iPhone Carnets App, but I can’t search the correct path. If someone can help me.

The dataset I download from Kaggle. Are free files that I push into a folder. I try this code:

import pandas as pd

aguacates = pd.read_excel("⁨⁨⁨En mi       iPhone⁩ ▸ ⁨video141_python_pildorasInfor⁩ ▸     Aguacate producción.xlsx")
print(aguacates)

And also this other:

import pandas as pd

aguacates = pd.read_excel("⁨⁨⁨En mi iPhone⁩ \\video141_python_pildorasInfor⁩\\Aguacate producción.xlsx")
(aguacates)

The error is:

`FileNotFoundError                         Traceback (most recent call last)
Cell In[2], line 3
  1 import pandas as pd
----> 3 aguacates = pd.read_excel("⁨⁨En mi iPhone⁩\\⁨video141_python_pildorasInfor⁩\\Aguacate producción.xlsx")
  4 print(aguacates)

File /private/var/containers/Bundle/Application/D169301A-0DB7-4982-8FE3-9C6D0E0C17D8/Carnets.app/Library/lib/python3.11/site-packages/pandas/io/excel/_base.py:478, in read_excel(io, sheet_name, header, names, index_col, usecols, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, parse_dates, date_parser, date_format, thousands, decimal, comment, skipfooter, storage_options, dtype_backend)
476 if not isinstance(io, ExcelFile):
477     should_close = True
--> 478     io = ExcelFile(io, storage_options=storage_options, engine=engine)
479 elif engine and engine != io.engine:
480     raise ValueError(
481         "Engine should not be specified when passing "
482         "an ExcelFile - ExcelFile already has the engine set"
483     )

File /private/var/containers/Bundle/Application/D169301A-0DB7-4982-8FE3-9C6D0E0C17D8/Carnets.app/Library/lib/python3.11/site-packages/pandas/io/excel/_base.py:1496, in ExcelFile.__init__(self, path_or_buffer, engine, storage_options)
   1494     ext = "xls"
   1495 else:
-> 1496     ext = inspect_excel_format(
   1497         content_or_path=path_or_buffer, storage_options=storage_options
   1498     )
   1499     if ext is None:
   1500         raise ValueError(
   1501             "Excel file format cannot be determined, you must specify "
   1502             "an engine manually."
   1503         )

File /private/var/containers/Bundle/Application/D169301A-0DB7-4982-8FE3-9C6D0E0C17D8/Carnets.app/Library/lib/python3.11/site-packages/pandas/io/excel/_base.py:1371, in inspect_excel_format(content_or_path, storage_options)
   1368 if isinstance(content_or_path, bytes):
   1369     content_or_path = BytesIO(content_or_path)
-> 1371 with get_handle(
   1372     content_or_path, "rb", storage_options=storage_options, is_text=False
   1373 ) as handle:
   1374     stream = handle.handle
   1375     stream.seek(0)

File /private/var/containers/Bundle/Application/D169301A-0DB7-4982-8FE3-9C6D0E0C17D8/Carnets.app/Library/lib/python3.11/site-packages/pandas/io/common.py:868, in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
    859         handle = open(
    860             handle,
    861             ioargs.mode,
   (...)
    864             newline="",
    865         )
    866     else:
    867         # Binary mode
--> 868         handle = open(handle, ioargs.mode)
    869     handles.append(handle)
    871 # Convert BytesIO or file objects passed with an encoding

FileNotFoundError: [Errno 2] No such file or directory: '\u2068\u2068En mi iPhone\u2069\\\u2068video141_python_pildorasInfor\u2069\\Aguacate producción.xlsx'`
Share Improve this question asked Mar 9 at 3:23 Samusdr17Samusdr17 1 5
  • 1 maybe use os.listdir() to check files in current working folder, and os.listdir("..") to check parent folder, and os.listdir("../..") another level. This way you could check structure of folders - and see if folders has names as you expect. You may also start from root folder - os.listdir("/"). – furas Commented Mar 9 at 8:33
  • 1 you use relative path and it may not exists in current working directory (os.getcwd()) but maybe you should create /full/path/to/file or add .., ../.., etc. in your path if you need relative path. – furas Commented Mar 9 at 8:35
  • 1 btw; pandas can read file from web servers pd.read_excel("https://....xlsx") so you may try to load it directly from Kaggle. But first check if this file can be downloaded when you are not logfed in on Kaggle because some information needs to be logged in. – furas Commented Mar 9 at 8:37
  • btw: error shows path /private/../.../ with / - so you can also use / instead of \\ – furas Commented Mar 9 at 8:39
  • Thank you so much @furas. In PC dont have any problems, but in iPhone is a new challenge – Samusdr17 Commented Mar 9 at 22:38
Add a comment  | 

1 Answer 1

Reset to default 0

Due to iOS peculiarities, a notebook in Carnets can not open files at arbitrary locations (using an absolute path). It is easier to have the data file and the notebook in the same folder, and use a relative path:

aguacates = pd.read_excel("⁨⁨⁨Aguacate producción.xlsx") 

I'm the author of Carnets.

本文标签: pythonHow to import xlsx in Jupyter Notebook from iPhone Carnets AppStack Overflow