Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

when pyspark

from pyspark.sql.functions import when
df2 = df.withColumn("new_gender", when(df.gender == "M","Male")
                                 .when(df.gender == "F","Female")
                                 .when(df.gender.isNull() ,"")
                                 .otherwise(df.gender))
df2.show()
+-------+------+------+----------+
|   name|gender|salary|new_gender|
+-------+------+------+----------+
|  James|     M| 60000|      Male|
|Michael|     M| 70000|      Male|
| Robert|  null|400000|          |
|  Maria|     F|500000|    Female|
|    Jen|      |  null|          |
+-------+------+------+----------+
Comment

PREVIOUS NEXT
Code Example
Python :: ssl unverified certificate python 
Python :: list to string python 
Python :: extract image from pdf python 
Python :: pandas remove rows with null in column 
Python :: face detection 
Python :: import static in django urls 
Python :: all permutations python 
Python :: clear pygame screen 
Python :: python for loop m to n 
Python :: rabbitmq pika username password 
Python :: plot pandas figsize 
Python :: pyspark select without column 
Python :: dictionary in python does not support append operation 
Python :: get number of string python 
Python :: Remove the First Character From the String in Python Using the Slicing 
Python :: remove duplicates without changing order python 
Python :: django import timezone 
Python :: how to print hello in python 
Python :: print last n rows of dataframe 
Python :: how to drop a column by name in pandas 
Python :: django.db.utils.OperationalError: no such table: 
Python :: how to move a column to last in pandas 
Python :: python os exists 
Python :: email authentication python 
Python :: create django user command line 
Python :: cosine similarity python numpy 
Python :: python math cube root 
Python :: python time function duration and memory usage 
Python :: simulated annealing python 
Python :: python exceute 60 records per minute counter 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =