尝试在jupyter noteb中打印数据帧时发生类型错误

2024-09-30 18:34:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个在python中定义的示例dataframe:

df = pd.DataFrame({
  'col1': ['Item0', 'Item0', 'Item1', 'Item1'],
  'col2': ['Gold', 'Bronze', 'Gold', 'Silver'],
  'col3': [1, 2, np.nan, 4]
   })

当我试着在jupyter笔记本上打印数据框df时,只需键入 在jupyter中执行df时,我得到一个错误:

TypeError:不支持numpy boolean negative,-运算符,请改用~运算符或逻辑函数

我试过print(df),转换成html表并打印它,display(df)都显示出相同的错误。在

附言:印刷品(df)或只是df几个星期前在朱皮特工作得很好。在


Tags: 示例dataframedf定义错误jupyter运算符col2
3条回答

我刚刚在另一个设置中遇到了这个错误,我认为根本的问题是与Numpy 1.13不兼容,(临时)修复是用Numpy 1.12重新安装。在

导致错误的行为变化是,如果您尝试否定布尔值,Numpy现在会抛出一个错误: https://docs.scipy.org/doc/numpy/release.html#deprecationwarning-to-error

DeprecationWarning to error: negative(bool_), TypeError when negative applied to booleans.

它帮助我从pandas 0.13升级到0.20.3。在

尝试使用iloc

    df.iloc[0:5] #this will show first 5 rows of the dataframe

有关详细信息,请访问http://www.shanelynn.ie/select-pandas-dataframe-rows-and-columns-using-iloc-loc-and-ix/

相关问题 更多 >