 Hello, welcome to SSUnitex, so see this side and this is continuation of PySpark tutorial. So in this video, we are going to see about the for each loop. So for each loop is very important concept inside the PySpark. So what is the for each loop basically for each is an active operation in the spark that is available with data frame, RDD and data sets in PySpark to iterate over each element in the data set. So let's assume if we are having a data frame and it is having total five rows and those rows could be having something like the country. So the requirement is we just want to iterate with each country. Those are available on the particular data frame. So here we are having total five rows. So your for each loop will be going to execute five times one for each row. So let me quickly go inside the browser and we'll try to see in practical. So here I have already created one of the mount point with input location. So we can execute this and we'll see the output. So here we can see it is having total four columns, first is the path, the name, then size, then modification date. So our requirement is we just want to loop through with each row as we can see total six rows are here. So we just want to look through with each row and then we will be filtering only for the JSON files and that JSON file will be processed. So how we can do that? So for that we have to use the for each loop. So it's very straightforward for using the for each loop. First we have to specify for then we have to specify one of the variable. So I'm calling this as I then in and after that we have to specify the data frame. So we have not put this value in the data frame. So first let me put this into the data frame. So we can have df equals to this. Let me execute it. So come on executed successfully. Now data frame is created and the data frame that is df. So this for loop will be going to execute all the elements. Those are available in the data frame that is df. So here we can see six rows. So this loop will be executing six times and I will be holding the value for that particular data frame for one by one. So after that we can put enter and let me try to print I. So here I then we have to specify the index like which column we want to display. So let me try to display the column first. That is the path. Let me try to execute and we'll see the output of this. So as we could see here we are having total six values for one for each row. So here if you are going to specify index as one and we can execute then we'll be going to see the second column that is the file name and in the output we can see the file name. But the actual requirement we are going to process only JSON files but here we have all these files. So how we can do that? So for that we have to use the if clause and inside the if clause we have to specify if your file path or file name will be containing JSON. In your data frame that is df and df inside the for each loop will be having I. So I1 and we can provide this column and in this print we can execute and we'll see. We can see it is filtered only for the JSON file that we can see. So first we have the for each loop and it will be executing total six times but under that we are checking if your file name is containing .json then we are printing. So it is filtering for that JSON and we are having total four here. But our next requirement we just want to process only those JSON files for those size is less than 400. So as you can see the size column so in the if clause we can add one more condition and here we can add the condition as and and after that I then we can see 0 1 2. So size is the index 2 if this value is less than 400 we can close the bracket and let me try to execute and we'll see the output. So now we can see it is having total three values those are having size less than 400 and those files are JSON. So now we can see we can process all these files whatever the logic we want we can simply write here and we can check the output of those. So I hope guys you have understood how we can use for each loop if you like this video please subscribe our channel to get many more videos see you in the next video.