我有一个熊猫数据框。我想保留数字列和特定的列名称。我怎么做?
In [11]: df = pd.DataFrame([[68, 'DC', 'three', 'Sunny', 'Chance of Rain']], columns=['A', 'B', 'C', 'D', 'E'])
In [12]: df.select_dtypes(include=['number'])
Out[12]:
A
0 68
我想创建以下数据框。
A D E
0 68 Sunny Chance of Rain
我将union
使用列标题,然后在数据框上使用列过滤。
df[df.select_dtypes(include=['number']).columns.union(['D', 'E'])]
输出:
A D E
0 68 Sunny Chance of Rain
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句