我在 Pyspark (2.1.0) 中有一个 Spark DataFrame,我希望仅获取数字列或字符串列的名称。
例如,这是我的 DF 的架构:
root
|-- Gender: string (nullable = true)
|-- SeniorCitizen: string (nullable = true)
|-- MonthlyCharges: double (nullable = true)
|-- TotalCharges: double (nullable = true)
|-- Churn: string (nullable = true)
这是我需要的:
num_cols = [MonthlyCharges, TotalCharges]
str_cols = [Gender, SeniorCitizen, Churn]
我怎样才能做到?
最佳答案
dtypes 是您可以使用简单过滤器的元组列表(columnNane,type)
columnList = [item[0] for item in df.dtypes if item[1].startswith('string')]
关于python - 仅从 pyspark 中的 Spark DF 选择数字/字符串列名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44066635/