我有一个包含列:[A, B, ... M]和一个只需要从dataframe中获取很少列的模式的dataframe:
StructType([StructField(A, StringType(), False),
            StructField(C, StringType(), True),
            StructField(K, StringType(), True)])由于我不拥有架构,所以我没有所有列的列表。是否有一种安全有效地按照模式选择列的方法?
发布于 2021-03-20 05:01:22
让我们说,您的模式是
schema = StructType([StructField(A, StringType(), False),
            StructField(C, StringType(), True),
            StructField(K, StringType(), True)])要从dataframe中选择这些列,您可以这样做
df.select([col for col in schema])https://stackoverflow.com/questions/66717354
复制相似问题