Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何删除列中包含“-”的所有行?
我努力了:
df1['Refl'] = df1['Refl'].str.replace('-', 'NaN').astype(int)
但得到后续错误:ValueError:无法将浮点 NaN 转换为整数
您找到带有“-”的行的索引并将它们也删除。
idx = df1[df1['Ref1'] == '-'].index df1.drop(idx , inplace=True)
尝试这个:
df1 = df1[~df1['Refl'].eq('-')]
另一种解决方案:
df1['Refl'] = df1['Refl'].replace('-': np.nan) df1 = df1.dropna(subset='Refl')