是否有任何Pyspark UDF函数或内置功能可用于在数据框中添加新列并根据行值进行行级操作?
我有一个类似的数据框:
| col1 | col2 |
--------------
| a | 1 |
| a | 2 |
| b | 3 |
| c | 4 |
| a | 5 |
现在,我需要创建新的列“ Col3”,并且必须根据Col1值将新值放在Col3中。最终的数据帧看起来像这样。
就像,如果Col1具有“ A”的值,则Col3应该在其中具有“苹果”。 如果Col1具有“ B”的价值,则Col3应该在其中有“香蕉”。 如果Col1具有“ C”的价值,则Col3应该在其中具有“蛋ust”。
注意:COL2是正常的列,请不要考虑。
| col1 | col2 | col3 |
------------------------
| a | 1 |apple |
| a | 2 |apple |
| b | 3 |banana |
| c | 4 |custard |
| a | 5 |apple |
我可以获得的任何pyspark UDF或内置功能吗?
提前致谢!!!
I have a dataframe like this:
| col1 | col2 |
--------------
| a | 1 |
| a | 2 |
| b | 3 |
| c | 4 |
| a | 5 |
Now, I need to create new column 'col3' and i have to put new values in col3 based on col1 value. The resultant dataframe would look like this.
Like, if col1 has the value 'a', then col3 should have "apple" in it.
if col1 has the value 'b', then col3 should have "banana" in it.
if col1 has the value 'c', then col3 should have "custard" in it.
Note: col2 is normal column, Please don't consider.
| col1 | col2 | col3 |
------------------------
| a | 1 |apple |
| a | 2 |apple |
| b | 3 |banana |
| c | 4 |custard |
| a | 5 |apple |
Any Pyspark UDF or Inbuilt function i can get?
Thanks in Advance!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DataFram记录:
输出:
datafram records:
output:
我得到了这个功能的答案。这可能对某人有帮助。
我使用了此功能:
修改后的变量!!!
I got an Answer by this function.. This could be helpful for someone.
I have used this function:
Modified variables!!!