Session Ready
Exercise

IDs with different partitions

You've just completed adding an ID field to a DataFrame. Now, take a look at what happens when you do the same thing on DataFrames containing a different number of partitions.

To check the number of partitions, use the method .rdd.getNumPartitions() on a DataFrame.

The spark session and two DataFrames, voter_df and voter_df_single, are available in your workspace. The instructions will help you discover the difference between the DataFrames. The pyspark.sql.functions library is available under the alias F.

Instructions
100 XP
  • Print the number of partitions on each DataFrame.
  • Add a ROW_ID field to each DataFrame.
  • Show the top 10 IDs in each DataFrame.