2024-04-25 06:39:32 发布
网友
是否有方法检查数据帧的特定行和列中的特定值是否为nan?
我试过np.isnan(df.loc[no,'LatinDesc') 其中no是行no,但我得到以下错误:
输入类型不支持ufunc“isnan”,并且无法根据强制转换规则“safe”将输入安全强制转换为任何受支持的类型
您可以为此使用内置的pandas功能。举例说明:
import pandas as pd import numpy as np df = pd.DataFrame({'col1': np.random.rand(100), 'col2': np.random.rand(100)}) # create a nan value in the 10th row of column 2 df.loc[10, 'col2'] = np.nan pd.isnull(df.loc[10, :]) # will give true for col2
您可以为此使用内置的pandas功能。举例说明:
相关问题 更多 >
编程相关推荐