小编Nic*_*rpe的帖子

如何删除 pandas 数据框中带有 NaN 的行?

我有这个 pandas 数据框,它实际上是一个 Excel 电子表格:

    Unnamed: 0  Date    Num     Company     Link    ID
0   NaN     1990-11-15  131231  apple...    http://www.example.com/201611141492/xellia...   290834
1   NaN     1990-10-22  1231    microsoft http://www.example.com/news/arnsno...     NaN
2   NaN     2011-10-20  123     apple   http://www.example.com/ator...  209384
3   NaN     2013-10-27  123     apple...    http://example.com/sections/th-shots/2016/...   098
4   NaN     1990-10-26  123     google  http://www.example.net/business/Drugmak...  098098
5   NaN     1990-10-18  1231    google...   http://example.com/news/va-rece...  NaN
6   NaN     2011-04-26  546     amazon...   http://www.example.com/news/home/20160425...    9809
Run Code Online (Sandbox Code Playgroud)

我想删除列NaN中的所有行ID并重新索引“索引假想列”:

    Unnamed: 0  Date    Num     Company     Link    ID
0   NaN     1990-11-15  131231  apple...    http://www.example.com/201611141492/xellia...   290834 …
Run Code Online (Sandbox Code Playgroud)

python python-3.x pandas

4
推荐指数
1
解决办法
9608
查看次数

Pytorch CPU 设备索引不能为负数

我有一个用 cuda 训练的张量,我想将其部署在 CPU 上。我让模型在Google Colab GPU 运行时上运行,切换到 CPU 运行时并尝试将其移植。

很抱歉没有包含可重现的示例,如果数据集位于我的谷歌驱动器上,我真的不知道最佳实践是什么。

model = mymodel()
device = torch.device("cpu")
state_dict = torch.load(loadckpt,map_location=device)
model.load_state_dict(state_dict['model'])
model.eval()
result = model(sample)
Run Code Online (Sandbox Code Playgroud)

当我运行这个时,我收到以下回溯错误

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-25-5336d222ce8f> in <module>()
      8 # right_pad_np = sample["right_pad"]
      9 # disp_est_uint = np.round(disp_est_np * 256).astype(np.uint16)
---> 10 test_sample(sample)

8 frames
/content/CFNet/utils/experiment.py in wrapper(*f_args, **f_kwargs)
     28     def wrapper(*f_args, **f_kwargs):
     29         with torch.no_grad():
---> 30             ret = func(*f_args, **f_kwargs)
     31         return ret
     32 

<ipython-input-25-5336d222ce8f> in test_sample(sample)
      2 def …
Run Code Online (Sandbox Code Playgroud)

python torch

1
推荐指数
1
解决办法
2544
查看次数

标签 统计

python ×2

pandas ×1

python-3.x ×1

torch ×1