PySpark
- Spark 는 대용량 데이터 처리를 위한 엔진이며 머신 러닝 또는 데이터 분석 작업용 분산 컴퓨팅을 가능하게 한다.
- PySpark 는 Spark 의 Python API 이다.
- Python 보다 10배 이상 빠른 Scala 언어도 있지만 Python 이 학습곡선 등을 이유로 빠르게 채택되고 있다.
Spark 구성 모듈
- Spark SQL
- Spark Streaming
- Spark MLLib - for machine learning
- Spark GraphX - for visualization
Loading Dataset
- dataframe : 2-dimensinal labled data structor with cloumns of potentially different types
- ways to view dataframe in PySpark
df.take(n) df.collect() df.show() df.limit(n), df.limit()
- viewing dataframe columns :
df.columns
- dataframe schema :
df.dtypes df.printSchema()
- Inferring Schema Implicitly :
inferSchema=True
- Defining Schema Explicitly : label → StructType → schema=StructType instance
DataFrame Operations on Columns
- Selecting Columns
- Selecting Multiple Columns
df.select(df.ColumnName).show()
df.select(df['c1'], df['c2']).show()