简体   繁体   English

如何处理pyspark数据框列

[英]How to process pyspark dataframe columns

I have a pyspark df with >4k columns without any labels/headers. 我有一个带有> 4k列的pyspark df,没有任何标签/标题。 Based on the column values I need apply specific operations on each columns. 基于列的值,我需要在每列上应用特定的操作。

I did the same using pandas but I don't want to use pandas and would like to apply the column wise transformation directly on spark dataframe. 我使用pandas进行了相同的操作,但是我不想使用pandas,而是希望将列明智的转换直接应用于spark数据框。 any idea as how can i apply column wise transformation if the df is having >4k columns without any label.also I don't want to apply transformations on specific df column index. 任何想法,如果df有> 4k列而没有任何标签,我如何应用列明智的转换。我也不想在特定的df列索引上应用转换。

According to the Spark documentation, a dataframe contains - unlike what you said - headers, much like a database table. 根据Spark文档,与您所说的不同,数据框包含标头,很像数据库表。

In any case, a simple for loop should do the trick: 无论如何,一个简单的for循环应该可以解决问题:

for column in spark_dataframe.columns:
    (do whatever you want to do with your columns)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM