I'm trying to fetch the number of partitions of a dataframe using this:
df.rdd.getNumPartitions.toString
But when I monitor the spark log, I see it spins up many stages and is a costly operation to have.

As per my understanding, dataframe adds a structural layer to rdd via metadata. So, how come stripping that while converting to rdd takes this much time?