Grouping data into batches in PySpark

Requirement

Create optimal batches of fruits with these constraints:

  • Each batch can have up to 50 fruits total
  • A maximum of 10 apples per batch
  • No restrictions on mangoes and bananas

Claude