 ఇర్నోలిలాడికిస్ల్నిట్త్రండింవారుదారంచి పోట్చి ఆ఩ోస్స్ పా్చినింటాట్నన్ండియాట్ట్ప్ట్ట్టంనిస్స్రులినాబ్ పరినానాహరోలి second is the with column so i have already explained about the select and with column in this playlist earlier so here you can see this is the syntax for using the when clause so first we are required to import the function and after that here we simply going to use the select and under this select first we are selecting all the columns so let's assume we are having total five columns in our data frame so first we want all those columns then we are going to add one more column and in this column first it is checking when item name value is total income then we are going to add the quantity those are having in the data frame plus hundred in the second condition if the item name is sales government funding grants and subsidies so on this it will be going to add 200 on the quantity similarly for the second item name and if all these condition will not be true then inside the otherwise this is the else part we are going to simply add 1000 and here we are going to provide the areas so this is the new quantity so this is the syntax that we will be using similarly we will be also seeing how we can use with column option let me quickly go inside the browser and we will try to implement it in practical so here we have this data frame which is a df and it is having sales data like sales order ID date, item code, item name and quantity now let me quickly scroll down and in the new cell here I am going to first import the function so we can use the from pyspark dot sql dot functions then import instead of specifying any function I am going to import all the functions so we can use the as thick first I am going to use by using the select statement so we can use the data frame dot select inside the bracket we can specify the as thick because we want all these columns let me put this in one of the data frame which is the df1 and let me try to display this df1 so what it is doing it is going to fetch all the columns from this data frame and we will be specifying that in df1 now the next I am going to use the when clause so for using the when clause we can simply use the when then we can start the bracket and inside this bracket we can specify the conditions so the condition will be your data frame that is df dot item name is equals to your total income so if this item name is having total income then what we want we want what will be the data frame quantity just adding 100 on this this is the first condition we have added for adding the second condition we simply add dot and then we can use again when clause for using the multiple when conditions we are required to use dot when then again inside the bracket simply use df dot item name if the item name value is equals to this value then we can simply add data frame dot quantity plus 200 similarly we can add one more condition so dot when here data frame dot item name value equals to this time I am going to use this interest one so we can add here if the item name value is this then simply we are going to use data frame plus 500 on the quantity now the last condition will be if all these conditions will not be satisfied then what we want to specify so simply we can use otherwise if we are not going to specify otherwise then it will be adding the null instead of this value so here I am going to add the value as 1000 now the last thing as let me try to execute this first so here inside this output we can see this column name so this column name is not proper it is having all the condition so what we are required to do in this scenario let me add the alias and in this alias we can add the column name may be quantity new and let me execute it so what we can see we are having the quantity new and this is calculated by using the when clause if the total income then quantity is 5 and it is adding 100 here so we can see 105 and if your item name is sales government then your quantity is 6 it will be adding 200 and new quantity will be 206 similarly we can see the third one for the interest one here it is adding 500 so the old quantity was 7 and after adding 500 now it is 507 for the other values as we can see 1000 so by using this method we can use it now let me try to use by using the with column so how we can do that instead of this select we can simply use with column and the first parameter will be the column name so I am going to specify the column name as quantity new let me try to remove this alias over here that's it only this change we are required to do so what this with column will do it will be going to add a new column on the existing data frame that is DF and it will be quantity new let me try to execute it and we will see the same output as we could see it is having the same output so either you can use the select or you can also use the with column so I hope guys you have understand how we can use the when clause so thank you so much for watching this video see you in the next video