【问题标题】:#Python importing data --Alex the analyst project#Python 导入数据——分析师项目Alex
【发布时间】:2021-12-04 06:40:13
【问题描述】:

我正在研究 Python/数据分析组合,正在观看 Alex the Analyst youtube 视频。 (https://www.youtube.com/watch?v=ocdwh0KYeUs&list=PLUaB-1hjhk8H48Pj32z4GZgGWyylqv85f&index=5)

但是,他提供的代码并不能正常工作。 我尝试了此代码 $ export XDG_RUNTIME_DIR=""(位于:Jupyter notebook permission error),但这也不起作用。

import pandas as pd 
import numpy as np 
import seaborn as sns 
import matplotlib.pyplot as plt 
import matplotlib.mlab as mlab 
import matplotlib 
plt.style.use('ggplot') 
from matplotlib.pyplot import figure 
%matplotlib inline 
matplotlib.rcParams['figure.figsize'] = (12,8) 
pd.options.mode.chained_assignment = None 
df = pd.read_csv(r'C:\Users\enana\Downloads\movies.csv')

我在做这个项目时只是想跟着做,所以我不太明白上面发生了什么。当我返回如下代码时,我不知道发生了什么:

PermissionError                           Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_18392/3202830863.py in <module>
     16 
     17 # Now we need to read in the data
---> 18 df = pd.read_csv(r'C:\Users\enana\Downloads\movies.csv')

~\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\parsers\readers.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 
--> 586     return _read(filepath_or_buffer, kwds)
    587 
    588 

~\anaconda3\lib\site-packages\pandas\io\parsers\readers.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:

~\anaconda3\lib\site-packages\pandas\io\parsers\readers.py in __init__(self, f, engine, **kwds)
    809             self.options["has_index_names"] = kwds["has_index_names"]
    810 
--> 811         self._engine = self._make_engine(self.engine)
    812 
    813     def close(self):

~\anaconda3\lib\site-packages\pandas\io\parsers\readers.py in _make_engine(self, engine)
   1038             )
   1039         # error: Too many arguments for "ParserBase"
-> 1040         return mapping[engine](self.f, **self.options)  # type: ignore[call-arg]
   1041 
   1042     def _failover_to_python(self):

~\anaconda3\lib\site-packages\pandas\io\parsers\c_parser_wrapper.py in __init__(self, src, **kwds)
     49 
     50         # open handles
---> 51         self._open_handles(src, kwds)
     52         assert self.handles is not None
     53 

~\anaconda3\lib\site-packages\pandas\io\parsers\base_parser.py in _open_handles(self, src, kwds)
    220         Let the readers open IOHandles after they are done with their potential raises.
    221         """
--> 222         self.handles = get_handle(
    223             src,
    224             "r",

~\anaconda3\lib\site-packages\pandas\io\common.py in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
    700         if ioargs.encoding and "b" not in ioargs.mode:
    701             # Encoding
--> 702             handle = open(
    703                 handle,
    704                 ioargs.mode,

PermissionError: [Errno 13] Permission denied: 'C:\\Users\\enana\\Downloads\\movies.csv'

请帮忙。

【问题讨论】:

标签: python jupyter-notebook importerror permission-denied permissionerror


【解决方案1】:

请尝试以下方法:在处理此类问题时,我们需要了解我们提供的路径应该是双“\”。

df = pd.read_csv(r"C:\\Users\\enana\\Downloads\\movies.csv")

您的问题可能会得到解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-26
    • 1970-01-01
    • 1970-01-01
    • 2016-04-17
    • 1970-01-01
    • 2018-08-14
    • 2017-12-09
    • 1970-01-01
    相关资源
    最近更新 更多