Вам не нужны панды, используйте pySpark dataframe.describe () , чтобы найти все числовые и строки столбцы (это пропустит типы столбцов, такие как дата , отметка времени , массив , struct и т. Д.), А затем отфильтровать столбцы StringType () , используя информацию изdf.dtypes:
from datetime import datetime
df = spark.createDataFrame([ (1, 12.3, 1.5, 'test', 13.23, datetime(2019,9,23)) ], ['i1', 'd2', 'f3', 's4', 'd5', 'dt'])
# DataFrame[i1: bigint, d2: double, f3: double, s4: string, d5: double, dt: timestamp]
# find all numeric and string columns from df (remove the first column which is `summary`)
cols = df.limit(100).describe().columns[1:]
# ['i1', 'd2', 'f3', 's4', 'd5']
# get a mapping of column vs dtypes of the df:
dtype_mapping = dict(df.dtypes)
#{'d2': 'double',
# 'd5': 'double',
# 'dt': 'timestamp',
# 'f3': 'double',
# 'i1': 'bigint',
# 's4': 'string'}
# filter out string-type from cols using the above mapping:
numeric_cols = [ c for c in cols if dtype_mapping[c] != 'string' ]
# ['i1', 'd2', 'f3', 'd5']