티스토리 뷰
728x90
from pyspark.sql.functions import lit
df = sqlContext.createDataFrame(
[(1, "a", 23.0), (3, "B", -23.0)], ("x1", "x2", "x3"))
df_with_x4 = df.withColumn("x4", lit(0))
df_with_x4.show()
## +---+---+-----+---+
## | x1| x2| x3| x4|
## +---+---+-----+---+
## | 1| a| 23.0| 0|
## | 3| B|-23.0| 0|
## +---+---+-----+---+
How do I add a new column to a Spark DataFrame (using PySpark)?
I have a Spark DataFrame (using PySpark 1.5.1) and would like to add a new column. I've tried the following without any success: type(randomed_hours) # => list # Create in Python and transfor...
stackoverflow.com
728x90
'공부' 카테고리의 다른 글
[Python] Split string every nth character? (0) | 2021.09.11 |
---|---|
[Linux] check DNS (0) | 2021.09.11 |
[Java][Spark] add column & default (0) | 2021.09.11 |
[Java][Spark] pyspark.sql.Row.asDict (0) | 2021.09.11 |
[Java][Spark] rename column - df = df.withColumnRenamed("colName", "newColName") (0) | 2021.09.11 |
[Java][Spark] new Row(**dict) (0) | 2021.09.11 |
댓글
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- 142,048
- Today
- 28
- Yesterday
- 221
TAG
- follower
- 김달
- 유투브
- Bot
- wlw
- 인스타그램
- 책그림
- 메디파크 내과 전문의 의학박사 김영수
- 어떻게 능력을 보여줄 것인가?
- 팔로워 수 세기
- Kluge
- 개리마커스
- 연애학개론
- COUNT
- 클루지