<jupyter_start><jupyter_text>Pyspark GroupBy And Aggregate Functions<jupyter_code>from pyspark.sql import SparkSession
spark=SparkSession.builder.appName('Agg').getOrCreate()
spark
df_pyspark=spark.read.csv('test3.csv',header=True,inferSchema=True)
df_pyspark.show()
df_pyspark.printSchema()
## Groupby
### Grouped to find the maximum salary
df_pyspark.groupBy('Name').sum().show()
df_pyspark.groupBy('Name').avg().show()
df_pyspark.groupBy('Name').max().show()
### Groupby Departmernts  which gives maximum salary
df_pyspark.groupBy('Departments').sum().show()
df_pyspark.groupBy('Departments').mean().show()
df_pyspark.groupBy('Departments').count().show()
df_pyspark.agg({'Salary':'sum', 'Departments':'max'}).show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17623497997329773, 'fraction_numerical': 0.0013351134846461949, 'mean_word_length': 10.194029850746269, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '660067', 'license': 'MIT', 'n_tokens_mistral': 284, 'n_tokens_neox': 270, 'n_words': 34, 'path': 'Group by and Aggregation.ipynb', 'repo_name': 'Hacker-Davinci/Pyspark_Basics_and_Projects', 'size': '749'}