- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在 Jupyter Notebook 中。我使用这些库:
from fastai.tabular import add_datepart
import pandas as pd
df_raw
是一个 pd 数据帧。
我遇到了这个非常奇怪的问题,当我使用第二个命令然后使用第一个命令重新运行单元时,第一个命令将停止工作:
首先:
>>> add_datepart(df_raw, 'saledate')
第二个:
>>> df_raw.saleYear.head()
这是我得到的错误:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2656 try:
-> 2657 return self._engine.get_loc(key)
2658 except KeyError:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'saledate'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-43-6b52dab581de> in <module>()
----> 1 add_datepart(df_raw, 'saledate')
~/anaconda3/lib/python3.6/site-packages/fastai/tabular/transform.py in add_datepart(df, field_name, prefix, drop, time)
55 def add_datepart(df:DataFrame, field_name:str, prefix:str=None, drop:bool=True, time:bool=False):
56 "Helper function that adds columns relevant to a date in the column `field_name` of `df`."
---> 57 make_date(df, field_name)
58 field = df[field_name]
59 prefix = ifnone(prefix, re.sub('[Dd]ate$', '', field_name))
~/anaconda3/lib/python3.6/site-packages/fastai/tabular/transform.py in make_date(df, date_field)
10 def make_date(df:DataFrame, date_field:str):
11 "Make sure `df[field_name]` is of the right date type."
---> 12 field_dtype = df[date_field].dtype
13 if isinstance(field_dtype, pd.core.dtypes.dtypes.DatetimeTZDtype):
14 field_dtype = np.datetime64
~/anaconda3/lib/python3.6/site-packages/pandas/core/frame.py in __getitem__(self, key)
2925 if self.columns.nlevels > 1:
2926 return self._getitem_multilevel(key)
-> 2927 indexer = self.columns.get_loc(key)
2928 if is_integer(indexer):
2929 indexer = [indexer]
~/anaconda3/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2657 return self._engine.get_loc(key)
2658 except KeyError:
-> 2659 return self._engine.get_loc(self._maybe_cast_indexer(key))
2660 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
2661 if indexer.ndim > 1 or indexer.size > 1:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'saledate'
我从来没有遇到过这样的问题,也不知道是 pandas、fastai 还是 jupyter 引起的。你能帮忙吗?
编辑:我什至不确定它是否只是同时使用这两个命令。现在我在没有第二个命令的情况下得到了错误...当我一起运行所有单元格时它会编译,但是一旦我用“第一个”命令重新运行那个单元格,这个单元格就会崩溃。
最佳答案
在docs ,看起来默认情况下 add_datepart 函数会从原始 DataFrame 中删除输入列。静静地发生这种情况似乎有点草率,但显然您可以通过传递 drop=False
来禁用该行为。
所以你的电话是
add_datepart(df_raw, 'saledate', drop=False)
关于python - 木星 : Why does this second command stop the first one from working?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55502680/
我的 Jupyter 配置如下: # encoding=utf-8 c = get_config() c.IPKernelApp.pylab = 'inline' c.NotebookApp.cert
我的 build.gradle 有: testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.0' 使用 http://junit.org/junit
这个问题在这里已经有了答案: Displaying rotatable 3D plots in IPython or Jupyter Notebook (6 个答案) 关闭 5 年前。 我不确定如何
我已经运行一个特定的 python 脚本有一段时间了。在此之前的几个月里,所有脚本都运行良好(包括在 Jupyter 中)。现在,不知何故,我系统中的 jupyter 开始在代码的一个特定行(下面提到
谷歌确实有很多解决这个问题的方法,但不幸的是,即使在尝试了所有的可能性之后,我还是无法让它工作,所以请耐心等待,看看是否有什么让你印象深刻。 操作系统:MAC 星火:1.6.3 (2.10) Jupy
我经常使用Jupyter的cell magic命令 %%px --targets 3 #Some code 在 3 号簇上运行一些代码。使用 line 魔术命令获得相同结果的语法是什么? 我试过了 %
请参阅随附的屏幕截图: 在 Jupyter Python 中:是否有将单元格的输出复制到剪贴板的快捷方式? (即无需手动选择和 ctrl-c?) 或者是否有一个 python 函数可以代替 print
我的路径中有 2 个 csv 文件。我想在不阅读的情况下连接或合并 2 个文件。这是针对数据加载问题和合并错误(大量数据) my folder/a.csv my folder/b.csv 使用>制作a
我喜欢使用 jupyter notebook 来记录我的物理类(class)的主题,所以我让我的学生使用 CoCalc 和 Markdown 或 Jupyter notebook 来编写他们的实验报告
我正在尝试使用神奇的 %run -d "/home/dev/filename.py" 在 Debug模式下在 Jupyter Notebook 中运行脚本。 我在这样做时收到错误:AttributeE
我尝试对我的 toggleButton 使用 observe wtarget = widgets.ToggleButtons( description='select target',
我在 Jupyter Notebook 中。我使用这些库: from fastai.tabular import add_datepart import pandas as pd df_raw 是一个
我定义了自己的 JUnit 注释: @ParameterizedTest @MethodSource("myorg.qa.ccrtesting.DataProviders#standardDataPr
我正在尝试在全新安装的 Ubuntu 19.04 上使用 Jupyter notebook。我已经完成了通常的安装步骤,但 Jupyter 不起作用。当我尝试打开一个笔记本时,我得到了 500 : I
我最近切换到 VSCode,想知道是否有办法让 VSCode 中的 Jupyter 支持的 Python 交互式窗口像 Spyder 中的控制台一样工作,我只需要选择代码并按 ctrl+enter 发
我是一名优秀的程序员,十分优秀!