как удалить именную ошибку Traceback (последний вызов был последним) - PullRequest
1 голос
/ 02 июня 2019

Я делаю серию, используя три словаря, в словаре нет ключевого слова или значений "name" / "null". Но это показывает NameError: имя 'null' не определено

перезапустить код в другом блокноте jupyter

import pandas as pd
p1=pd.Series({'team':'england','keyplayer':'joe root','bowler':'jofra'})
p2=pd.Series({'team':'india','keyplayer':'virat kohli','bowler':'bumhra'})
p3=pd.Series({'team':'australia','keyplayer':'steve smith','bowler':'starc'})
df=pd.DataFrame([p1,p2,p3],index=['1','2','3'])

df.head()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
~\Anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
    700                 type_pprinters=self.type_printers,
    701                 deferred_pprinters=self.deferred_printers)
--> 702             printer.pretty(obj)
    703             printer.flush()
    704             return stream.getvalue()

~\Anaconda3\lib\site-packages\IPython\lib\pretty.py in pretty(self, obj)
    400                         if cls is not object \
    401                                 and callable(cls.__dict__.get('__repr__')):
--> 402                             return _repr_pprint(obj, self, cycle)
    403 
    404             return _default_pprint(obj, self, cycle)

~\Anaconda3\lib\site-packages\IPython\lib\pretty.py in _repr_pprint(obj, p, cycle)
    695     """A pprint that just redirects to the normal repr function."""
    696     # Find newlines and replace them with p.break_()
--> 697     output = repr(obj)
    698     for idx,output_line in enumerate(output.splitlines()):
    699         if idx:

~\Anaconda3\lib\site-packages\pandas\core\base.py in __repr__(self)
     80         Yields Bytestring in Py2, Unicode String in py3.
     81         """
---> 82         return str(self)
     83 
     84 

~\Anaconda3\lib\site-packages\pandas\core\base.py in __str__(self)
     59 
     60         if compat.PY3:
---> 61             return self.__unicode__()
     62         return self.__bytes__()
     63 

~\Anaconda3\lib\site-packages\pandas\core\frame.py in __unicode__(self)
    661             width = None
    662         self.to_string(buf=buf, max_rows=max_rows, max_cols=max_cols,
--> 663                        line_width=width, show_dimensions=show_dimensions)
    664 
    665         return buf.getvalue()


NameError: name 'null' is not defined 

---------------- после показа этой таблицы

1 Ответ

0 голосов
/ 02 июня 2019

Я попытался запустить ваш код в изолированной среде, и мне удалось!

IPython:

In [1]: import pandas as pd                                                                                                              

In [2]: p1=pd.Series({'team':'england','keyplayer':'joe root','bowler':'jofra'}) 
      : p2=pd.Series({'team':'india','keyplayer':'virat kohli','bowler':'bumhra'}) 
      : p3=pd.Series({'team':'australia','keyplayer':'steve smith','bowler':'starc'}) 
      : df=pd.DataFrame([p1,p2,p3],index=['1','2','3'])                                                                                  

In [3]: df.head()                                                                                                                        
Out[3]: 
        team    keyplayer  bowler
1    england     joe root   jofra
2      india  virat kohli  bumhra
3  australia  steve smith   starc

Я установил минимум, необходимый для запуска: numpy==1.16.4, pandas==0.24.2 e jupyter==1.0.0

Возможно, есть проблемы с вашими библиотеками,Я рекомендую вам попробовать запустить код с помощью virtualenv и установить необходимые библиотеки.Чтобы узнать больше, ничего лучше, чем сама документация Python: https://docs.python.org/3/tutorial/venv.html

...