def repartition_npartitions(df, npartitions):
 npartitions_ratio = (df.npartitions / npartitions)
 new_partitions_boundaries = [int((new_partition_index * npartitions_ratio)) for new_partition_index in range((npartitions + 1))]
 new_name = ('repartition-%d-%s' % (npartitions, tokenize(df)))
 dsk = {}
 for new_partition_index in range(npartitions):
  value = (pd.concat, [(df._name, old_partition_index) for old_partition_index in range(new_partitions_boundaries[new_partition_index], new_partitions_boundaries[(new_partition_index + 1)])])
  dsk[(new_name, new_partition_index)] = value
 divisions = [df.divisions[new_partition_index] for new_partition_index in new_partitions_boundaries]
 return DataFrame(merge(df.dask, dsk), new_name, df._meta, divisions)

def repartition_npartitions ( df , npartitions ) : npartitions_ratio = ( df . npartitions / npartitions ) new_partitions_boundaries = [ int ( ( new_partition_index * npartitions_ratio ) ) for new_partition_index in range ( ( npartitions + 1 ) ) ] new_name = ( 'repartition-%d-%s' % ( npartitions , tokenize ( df ) ) ) dsk = { } for new_partition_index in range ( npartitions ) : value = ( pd . concat , [ ( df . _name , old_partition_index ) for old_partition_index in range ( new_partitions_boundaries [ new_partition_index ] , new_partitions_boundaries [ ( new_partition_index + 1 ) ] ) ] ) dsk [ ( new_name , new_partition_index ) ] = value divisions = [ df . divisions [ new_partition_index ] for new_partition_index in new_partitions_boundaries ] return DataFrame ( merge ( df . dask , dsk ) , new_name , df . _meta , divisions )
repartition dataframe to a smaller number of partitions .