spark sql and dataframe solution .. df1 = df.groupBy("DeptName").agg(count(when(col("Gender")=='M',1)).alias("Male"),count(when(col("Gender")=='F',1)).alias("Female"),count('*').alias("Total")) df1.show() spark.sql(''' select DeptName,count(case when Gender = 'M' then 1 end ) as male, count(case when Gender = 'F' then 1 end ) as Female, count(*) as total_emp from dept group by DeptName ''').show()
@Javi-gp5jw3 ай бұрын
Great video! Very informative and well-explained. Another solution I tried was : df.groupBy("DeptName") .agg(count('Gender').alias("TotalEmp"), count_if(df12.Gender=='M').alias("MaleEmp"), count_if(df12.Gender=='F').alias("FemaleEmp"), )
@ssunitech68903 ай бұрын
Good, Keep Learning and please share videos to your friends
@rawat72035 ай бұрын
Please continue this series, thanks
@ssunitech68905 ай бұрын
Sure will record more videos on this playlist
@kt-qg7uv6 ай бұрын
Hello sir, I hope you are doing well. I am currently attending interviews I am facing difficulty to explain the SSIS projects in my Resume. Can you please help me with that. Please respond. Thank you
@ssunitech68906 ай бұрын
Yes, sure Please find below videos for your project: kzbin.info/aero/PLNRxk1s77zfjbCU-BgnER0hrnf4TvY5A3
@videodevloper2776 ай бұрын
Nice
@ssunitech68906 ай бұрын
Thanks, Please share to others
@userbayya6 ай бұрын
Pls keep code also in description
@ssunitech68906 ай бұрын
Sure
@ardsha5 ай бұрын
this will also bring the result : df.groupBy('DeptName').agg(count(df.Gender).alias('TotalEmp'),sum(when (df.Gender=='M',1)).alias('Male_count'),sum(when(df.Gender=='F',1)).alias('FemaleCount')).show()
@ssunitech68905 ай бұрын
Thanks Keep learning and growing 💗
@datasculptor2895Ай бұрын
As per your query, In case of HR the male count will be shown as null, but should be shown as 0. So , we need to add otherwise(0) condition as well to get 0 count.