たとえばパンダでは
data_df = (
pd.DataFrame(dict(col1=['a', 'b', 'c'], col2=['1', '2', '3']))
.pipe(lambda df: df[df.col1 != 'a'])
)
これはRのパイプに似ています %>%
PySparkに似たようなものはありますか?
では、のpyspark
助けを借りてこのパイプ機能を簡単に実現できると思いますpipeline
。
Example: Let's take the example you provided
val df = Seq(("a", 1), ("b", 2), ("c", 3)).toDF("col1", "col2")
df.show(false)
df.printSchema()
/**
* +----+----+
* |col1|col2|
* +----+----+
* |a |1 |
* |b |2 |
* |c |3 |
* +----+----+
*
* root
* |-- col1: string (nullable = true)
* |-- col2: integer (nullable = false)
*/
の場合.pipe(lambda df: df[df.col1 != 'a'])
、sparkを簡単に使用できますSQLTransformer
。したがって、カスタムトランスフォーマーを作成する必要はありません
val transform1 = new SQLTransformer()
.setStatement("select * from __THIS__ where col1 != 'a'")
val transform2 = new SQLTransformer()
.setStatement("select col1, col2, SQRT(col2) as col3 from __THIS__")
val pipeline = new Pipeline()
.setStages(Array(transform1, transform2))
pipeline.fit(df).transform(df)
.show(false)
/**
* +----+----+------------------+
* |col1|col2|col3 |
* +----+----+------------------+
* |b |2 |1.4142135623730951|
* |c |3 |1.7320508075688772|
* +----+----+------------------+
*/
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加