当前位置:网站首页>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边栏推荐
- LeetCode刷题——去除重复字母#316#Medium
- ssh/scp 使不提示 All activities are monitored and reported.
- 【idea】推荐一个idea翻译插件:Translation「建议收藏」
- Steps for Navicat to create a new database
- Leetcode skimming - remove duplicate letters 316 medium
- 6091. Divide the array so that the maximum difference is K
- [leetcode] 417 - Pacific Atlantic current problem
- [leetcode] 577 reverse word III in string
- 目标检测—利用labelimg制作自己的深度学习目标检测数据集
- 数字藏品系统开发(程序开发)丨数字藏品3D建模经济模式系统开发源码
猜你喜欢

03. Preliminary use of golang

Wechat Alipay account system and payment interface business process

03.golang初步使用

PTA 天梯赛习题集 L2-001 城市间紧急救援

二叉树前,中,后序遍历

LeetCode刷题——两整数之和#371#Medium

Steps for Navicat to create a new database

怎样从微信返回的json字符串中截取某个key的值?

已知兩種遍曆序列構造二叉樹

Leetcode skimming - remove duplicate letters 316 medium
随机推荐
Basic knowledge of cryptography
【LeetCode】189-轮转数组
[network security] network asset collection
[leetcode] 1020 number of enclaves
NBA player analysis
[leetcode] 200 number of islands
Pytoch saves tensor to Mat file
树-二叉搜索树
Cultural scores of summer college entrance examination
【idea】推荐一个idea翻译插件:Translation「建议收藏」
Engineer evaluation | rk3568 development board hands-on test
Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568
【LeetCode】695-岛屿的最大面积
【LeetCode】877-石子游戏
Name of institution approved in advance
Custom exception
LeetCode刷题——去除重复字母#316#Medium
【LeetCode】417-太平洋大西洋水流问题
6090. 极大极小游戏
beforeEach