当前位置:网站首页>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边栏推荐
- 士官类学校名录
- 党史纪实主题公益数字文创产品正式上线
- /bin/ld: 找不到 -lxml2
- MD5 encryption
- Engineer evaluation | rk3568 development board hands-on test
- 已知兩種遍曆序列構造二叉樹
- Party History Documentary theme public welfare digital cultural and creative products officially launched
- The task cannot be submitted after the installation of flick is completed
- 2278. 字母在字符串中的百分比
- Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568
猜你喜欢
随机推荐
LeetCode刷题——两整数之和#371#Medium
[development environment] install Visual Studio Ultimate 2013 development environment (download software | install software | run software)
C # get PLC information (kepserver) II
lseek 出错
Engineer evaluation | rk3568 development board hands-on test
04. Some thoughts on enterprise application construction after entering cloud native
6092. Replace elements in the array
数组和链表的区别浅析
(4) Flink's table API and SQL table schema
Leetcode skimming -- count the number of numbers with different numbers 357 medium
PostgresSQL 流复制 主备切换 主库无读写宕机场景
Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!
LeetCode刷题——递增的三元子序列#334#Medium
PTA 天梯赛习题集 L2-001 城市间紧急救援
[leetcode] 189 rotation array
02. After containerization, you must face golang
【LeetCode】977-有序數組的平方
微信支付宝账户体系和支付接口业务流程
【Experience Cloud】如何在VsCode中取得Experience Cloud的MetaData
[experience cloud] how to get the metadata of experience cloud in vscode

![[leetcode] 1905 statistics sub Island](/img/82/d2f7b829f5beb7f9f1eabe8d101ecb.png)






![[salesforce] how to confirm your salesforce version?](/img/ce/4c844b1b686397faa1b6aa3d57e034.png)