从"混合数据类型"列中提取所有整数行



我有一个数据帧,其中一列包含整数和字符串。有没有办法只对具有整数值的行进行筛选?

df[df['column'].type == int] ? 
df[df['column'].astype(str).str.isdigit()]

参考网址熊猫系列

https://pandas.pydata.org/pandas-docs/stable//reference/api/pandas.Series.str.isdigit.html

Series.str.isalpha
Check whether all characters are alphabetic.
Series.str.isnumeric
Check whether all characters are numeric.
Series.str.isalnum
Check whether all characters are alphanumeric.
Series.str.isdigit
Check whether all characters are digits.
Series.str.isdecimal
Check whether all characters are decimal.
Series.str.isspace
Check whether all characters are whitespace.
Series.str.islower
Check whether all characters are lowercase.
Series.str.isupper
Check whether all characters are uppercase.
Series.str.istitle
Check whether all characters are titlecase.
df['datatype'] = df['column'].apply(lambda x: 'int' if type(x) == int else 'str')
df[df['datatype'] == 'int']

使用lambda函数检查并标记每一行。将该行另存为新列,并对新列进行筛选。

相关内容

  • 没有找到相关文章

最新更新