当前位置:网站首页>Add an empty column to spark dataframe - add an empty column to spark dataframe
Add an empty column to spark dataframe - add an empty column to spark dataframe
2022-07-02 15:42:00 【Technology feast】
problem :
As mentioned in manyother locations on the web, adding a new column to an existing DataFrame is not straightforward. As on the Internet many Other places Described , To the present DataFrame Adding new columns is not easy .Unfortunately it is important to have this functionality (even though it is inefficient in a distributed environment) especially when trying to concatenate two DataFrame
s using unionAll
. Unfortunately , Try to connect two, especially when there is such a function ( Even if it is inefficient in a distributed environment ) It's important DataFrame
S Use unionAll
.
What is the most elegant workaround for adding a null
column to a DataFrame
to facilitate a unionAll
? take null
Columns added to DataFrame
In order to promote unionAll
The most elegant solution is unionAll
?
My version goes like this: My version is like this :
from pyspark.sql.types import StringTypefrom pyspark.sql.functions import UserDefinedFunctionto_none = UserDefinedFunction(lambda x: None, StringType())new_df = old_df.withColumn('new_column', to_none(df_old['any_col_from_old']))
Solution :
Reference resources : https://stackoom.com/en/question/2Ecs2边栏推荐
猜你喜欢
SQL transaction
2022 college students in Liaoning Province mathematical modeling a, B, C questions (related papers and model program code online disk download)
Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!
Leetcode question brushing - parity linked list 328 medium
Custom exception
终于搞懂了JS中的事件循环,同步/异步,微任务/宏任务,运行机制(附笔试题)
PTA ladder game exercise set l2-001 inter city emergency rescue
Evaluation of embedded rz/g2l processor core board and development board of Feiling
密码学基础知识
微信支付宝账户体系和支付接口业务流程
随机推荐
【Salesforce】如何确认你的Salesforce版本?
[leetcode] 977 - carré du tableau ordonné
高考分数线爬取
【LeetCode】877-石子游戏
解决BASE64Encoder报错的问题
高考录取分数线爬虫
【LeetCode】695-岛屿的最大面积
2278. 字母在字符串中的百分比
【idea】推荐一个idea翻译插件:Translation「建议收藏」
PTA ladder game exercise set l2-001 inter city emergency rescue
[leetcode] 877 stone game
Engineer evaluation | rk3568 development board hands-on test
(Video + graphic) machine learning introduction series - Chapter 5 machine learning practice
ssh/scp 使不提示 All activities are monitored and reported.
locate: 无法执行 stat () `/var/lib/mlocate/mlocate.db‘: 没有那个文件或目录
Redux - detailed explanation
Solve the problem of frequent interruption of mobaxterm remote connection
SQL stored procedure
2022 college students in Liaoning Province mathematical modeling a, B, C questions (related papers and model program code online disk download)
Loss function and positive and negative sample allocation: Yolo series