Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Erro ao chamar o pd

Boa noite.

Quando digito a função

pd.read_csv('dados/aluguel.csv')

retorna

NameError Traceback (most recent call last) Input In [10], in <cell line: 1>() ----> 1 pd.read_csv('dados/aluguel.csv')

NameError: name 'pd' is not defined

O que poderia ser?

2 respostas
solução!

Olá Diego, blz?

Então, pd é o "apelido" que por convenção damos a biblioteca do pandas.

Verifica essas duas opções.

  1. Se você já possui a biblioteca do pandas instalado. Se não basta rodar o comando pip install pandas no seu terminal.
  2. É preciso fazer a importação, import pandas as pd.
import pandas as pd

dados = pd.read_csv('dados/aluguel.csv')

Bons estudos :D

Segui todos os passos e mesmo assim não rodou, aparece a seguinte mensagem:

UnicodeDecodeError Traceback (most recent call last) Input In [6], in <cell line: 1>() ----> 1 dados = pd.read_csv('dados/aluguel.csv')

File ~\Anaconda3\lib\site-packages\pandas\util_decorators.py:311, in deprecate_nonkeyword_arguments..decorate..wrapper(args, **kwargs) 305 if len(args) > num_allow_args: 306 warnings.warn( 307 msg.format(arguments=arguments), 308 FutureWarning, 309 stacklevel=stacklevel, 310 ) --> 311 return func(args, **kwargs)

File ~\Anaconda3\lib\site-packages\pandas\io\parsers\readers.py:680, 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) 665 kwds_defaults = refinedefaults_read( 666 dialect, 667 delimiter, (...) 676 defaults={"delimiter": ","}, 677 ) 678 kwds.update(kwds_defaults) --> 680 return read(filepathor_buffer, kwds)

File ~\Anaconda3\lib\site-packages\pandas\io\parsers\readers.py:575, in read(filepathor_buffer, kwds) 572 validatenames(kwds.get("names", None)) 574 # Create the parser. --> 575 parser = TextFileReader(filepath_or_buffer, **kwds) 577 if chunksize or iterator: 578 return parser

File ~\Anaconda3\lib\site-packages\pandas\io\parsers\readers.py:933, in TextFileReader.init(self, f, engine, **kwds) 930 self.options["has_index_names"] = kwds["has_index_names"] 932 self.handles: IOHandles | None = None --> 933 self.engine = self.make_engine(f, self.engine)

File ~\Anaconda3\lib\site-packages\pandas\io\parsers\readers.py:1235, in TextFileReader.makeengine(self, f, engine) 1232 raise ValueError(msg) 1234 try: -> 1235 return mapping[engine](f, **self.options) 1236 except Exception: 1237 if self.handles is not None:

File ~\Anaconda3\lib\site-packages\pandas\io\parsers\c_parser_wrapper.py:75, in CParserWrapper.init(self, src, *kwds) 72 kwds.pop(key, None) 74 kwds["dtype"] = ensure_dtype_objs(kwds.get("dtype", None)) ---> 75 self._reader = parsers.TextReader(src, *kwds) 77 self.unnamed_cols = self.reader.unnamedcols 79 # error: Cannot determine type of 'names'

File ~\Anaconda3\lib\site-packages\pandas_libs\parsers.pyx:544, in pandas.libs.parsers.TextReader._cinit__()

File ~\Anaconda3\lib\site-packages\pandas_libs\parsers.pyx:633, in pandas.libs.parsers.TextReader.get_header()

File ~\Anaconda3\lib\site-packages\pandas_libs\parsers.pyx:847, in pandas.libs.parsers.TextReader.tokenize_rows()

File ~\Anaconda3\lib\site-packages\pandas_libs\parsers.pyx:1952, in pandas.libs.parsers.raiseparser_error()

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9c in position 11: invalid start byte