m0_53438630 2021-01-12 11:16 采纳率: 100%
浏览 49
已采纳

python where函数问题

import pandas as pd
from pandas import Series, DataFrame
import numpy as np

a = pd.Series([np.nan, 2.5, 0.0, 3.5, 4.5, np.nan],
              index = ['f', 'e', 'd', 'c', 'b', 'a'])
b = pd.Series([0, np.nan, 2., np.nan, np.nan, 5.],
              index = ['a', 'b', 'c', 'd', 'e', 'f'])

a
Out[11]:
f    NaN
e    2.5
d    0.0
c    3.5
b    4.5
a    NaN
dtype: float64

b
Out[12]:
a    0.0
b    NaN
c    2.0
d    NaN
e    NaN
f    5.0
dtype: float64

np.where(pd.isnull(a), b, a)
Out[13]: array([0. , 2.5, 0. , 3.5, 4.5, 5. ])

np.where(pd.isnull(b), b, a)
Out[14]: array([nan, nan,  0., nan, nan, nan])


谁帮忙解释一下np.where(pd.isnull(a), b, a) 和 np.where(pd.isnull(b), b, a)  是什么意思啊?谢谢。

  • 写回答

3条回答 默认 最新

  • BryceRui 2021-01-12 11:23
    关注

    np.where(pd.isnull(a), b, a) 就是把a里面是空的用b对应的值替换,不然还是用a的值

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用