我已经使用pyhive将数据从蜂巢提取到python中。现在,我从导入的数据创建了一个数据框。数据框中所有列的dtype是object。我想知道删除包含字母(非数字)的数据框中任何列的最佳方法吗?
df.select_dtypes(['number'])无法正常工作,因为我所有的列都是dtype = object。
答案 0 :(得分:0)
以下内容会将数字字符串转换为数字dtype,并仅从DataFrame中选择数字dtype。
#convert number columns to numeric
df=df.apply(pd.to_numeric, errors='ignore')
df=df.select_dtypes('number')