或者在你的情况下,特别是: source.select_dtypes(['number']) or source.select_dtypes([np.number]
31
它是一个私有方法,但它可以解决这个问题:source._get_numeric_data()
In [2]: import pandas as pd
In [3]: source = pd.DataFrame({'A': ['foo', 'bar'], 'B': [1, 2], 'C': [(1,2), (3,4)]})
In [4]: source
Out[4]:
A B C
0 foo 1 (1, 2)
1 bar 2 (3, 4)
In [5]: source._get_numeric_data()
Out[5]:
B
0 1
1 2
3 回答
要避免使用私有方法,您还可以使用select_dtypes,您可以在其中包含或排除所需的dtypes .
完全按照this post进入它 .
或者在你的情况下,特别是:
source.select_dtypes(['number']) or source.select_dtypes([np.number]
它是一个私有方法,但它可以解决这个问题:source._get_numeric_data()
我还有另一种可能的解决方案,用于删除具有2行代码的分类值的列,定义具有分类值列(第1行)的列表,并使用第2行删除它们 . df是我们的数据帧
df在放弃之前:
df放弃后: