此问题在此处已有答案:
How do I find numeric columns in Pandas?(15个回答)
16天前关闭
哪些pandas
方法可以用一行代码获得给定DataFrame
中具有数字dtypes
(所有大小,如uint8
,而不仅仅是64位的)的列的名称?注意:实际上有数百列,因此dtypes
(或其他向量化方法)应该用于检测数据类型。
import numpy as np
import pandas as pd
test_df = pd.DataFrame(data=[{"str_col": "some string",
"int_col": 0,
"float_col": 3.1415}])
test_df.dtypes[test_df.dtypes == np.dtype('float')].index.values[0]
# "float_col"
test_df.dtypes[test_df.dtypes == np.dtype('int')].index.values[0]
# "int_col"
# ?
# ["float_col", "int_col"]
字符串
1条答案
按热度按时间41zrol4v1#
要获取数值列,请执行以下操作:
字符串
测试结果:
型