当前位置:网站首页>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] 19 delete the penultimate node of the linked list
- (4) Flink's table API and SQL table schema
- MD5加密
- [experience cloud] how to get the metadata of experience cloud in vscode
- Party History Documentary theme public welfare digital cultural and creative products officially launched
- Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568
- How to intercept the value of a key from the JSON string returned by wechat?
- 解决BASE64Encoder报错的问题
- [salesforce] how to confirm your salesforce version?
- [leetcode] 977 square of ordered array
猜你喜欢

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

SQL stored procedure

LeetCode刷题——奇偶链表#328#Medium

党史纪实主题公益数字文创产品正式上线
![[experience cloud] how to get the metadata of experience cloud in vscode](/img/45/012c2265402ba1b44f4497f468bc61.png)
[experience cloud] how to get the metadata of experience cloud in vscode

5. Practice: jctree implements the annotation processor at compile time

Steps for Navicat to create a new database

SQL transaction

03. Preliminary use of golang

Bing.com网站
随机推荐
PTA 天梯赛习题集 L2-001 城市间紧急救援
[leetcode] 876 intermediate node of linked list
[network security] network asset collection
Beijing rental data analysis
Leetcode skimming -- incremental ternary subsequence 334 medium
【LeetCode】695-岛屿的最大面积
2278. Percentage of letters in string
Bing. Site Internet
[leetcode] 577 reverse word III in string
/bin/ld: 找不到 -lxml2
[leetcode] 167 - sum of two numbers II - enter an ordered array
Soul torture, what is AQS???
College entrance examination admission score line climbing
6092. 替换数组中的元素
fastjson List转JSONArray以及JSONArray转List「建议收藏」
NBA player analysis
2022 college students in Liaoning Province mathematical modeling a, B, C questions (related papers and model program code online disk download)
/bin/ld: 找不到 -lgssapi_krb5
[leetcode] 1020 number of enclaves
【LeetCode】977-有序數組的平方