我已經按照指示的方法,把給我的csv代碼移到我的Jupyter筆記本所在的同一檔案夾中。它仍然無法讀取它。我還試圖把它轉換成一個資料框架,并讓它進行 "描述"。我把代碼和錯誤貼在下面。請幫助我! 謝謝你的幫助!
import pandas as pd
fish = pd.read_csv('c:UsersManaconda3ScriptsFish')
fish2 = pd.DataFrame(fish)
fish2.to_csv('fishdata.csv')
fish2.description()
OSError Traceback (most recent call last)
~AppDataLocalTemp/ipykernel_11624/2289113011.py in <module>
----> 1 fish = pd.read_csv('c:UsersManaconda3ScriptsFish')
~anaconda3libsite-packagespandasutil\_decorators.py in wrapper(*args, **kwargs)
309 stacklevel=stacklevel。
310 )
--> 311 return func(*args, **kwargs)
312
313 return wrapper
~anaconda3libsite-packagespandasioparsers
eaders. py in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, error_bad_lines, warn_bad_lines, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options)
584 kwds.update(kwds_defaults)
585 585
--> 586 return _read(filepath_or_buffer, kwds)
587
588 587
~anaconda3libsite-packagespandasioparsers
eaders.py in _read(filepath_or_buffer, kwds)
480
481 # Create the parser.
--> 482 parser = TextFileReader(filepath_or_buffer, **kwds)
483
484 if chunksize or iterator:
~anaconda3libsite-packagespandasioparsers
eaders.py in __init__(self, f, engine, **kwds)
809 self.options["has_index_names"] = kwds["has_index_names"]
810811 self._engine = self._make_engine(self.engine)
812
813 def close(self)。
~anaconda3libsite-packagespandasioparsers
eaders.py in _make_engine(self, engine)
1038 )
1039 # error: "ParserBase "的引數太多。
-> 1040 return mapping[engine](self.f, **self.options) # type: ignore[call-arg]/span>
1041
1042 def _failover_to_python(self) 。
~anaconda3libsite-packagespandasioparsersc_parser_wrapper.py in __init__(self, src, **kwds)
49
50 # open handle
--> 51 self._open_handles(src, kwds)
52 assert self.handles is not None >。
53
~anaconda3libsite-packagespandasioparsersase_parser.py in _open_handles(self, src, kwds)
220讓讀者在完成打開IOHandles之后與他們的潛在提升。
221 ""
--> 222 self.handles = get_handle(
223 src,
224 "r",
~anaconda3libsite-packagespandasiocommon.py in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
699 如果 ioargs.encoding 和 "b" 不在 ioargs.mode 中。
700 # 編碼
--> 701 handle = open(
702 handle,
703 ioargs.mode,
OSError: [Errno 22] 無效引數: 'c:UsersMx07naconda3ScriptsFish' 。
uj5u.com熱心網友回復:
你可以嘗試重新命名你的檔案,在你的檔案名上附加.csv
uj5u.com熱心網友回復:
你需要指定檔案的擴展名,你正試圖讀取。 例如:對于csv檔案,你的代碼可以是這樣的
fish = pd.read_csv('c:UsersManaconda3ScriptsFish.csv'/span>)
或者如果你的檔案和你的代碼在同一個目錄下,你可以直接使用完整的檔案名
fish = pd.read_csv('Fish.csv')
uj5u.com熱心網友回復:
你被明確告知read_csv的引數是無效的。
OSError: [Errno 22] 無效引數。'c:UsersMx07naconda3ScriptsFish'] 無效引數。
看來你漏掉了cvs檔案,比如說table.csv。
你可以嘗試使用os.getcwd()來檢查當前作業目錄是否與csv檔案相同。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/332405.html
標籤:
