Plots boxplots for specified columns of a DataFrame using PySpark.

Parameters:
  • df (DataFrame) –

    Input PySpark DataFrame to be plotted.

  • columns (list) –

    List of column names to plot.

Returns:
  • None( None ) –

    Displays the boxplots.

Raises:
  • ValueError

    If any column in the list is not numeric.

Examples:

>>> from pyspark.sql import SparkSession
>>> from pyspark.sql.types import StructType, StructField, IntegerType
>>> spark = SparkSession.builder.getOrCreate()
>>> schema = StructType([
...     StructField("id", IntegerType(), True),
...     StructField("score1", IntegerType(), True),
...     StructField("score2", IntegerType(), True)
... ])
>>> data = [(1, 10, 15), (2, 15, 20), (3, 25, 30), (4, 5, 12)]
>>> df = spark.createDataFrame(data, schema)
>>> plot_boxplots(df, ["score1", "score2"])

Logs:

  • INFO: Plotting boxplot for column: score1
  • INFO: Plotting boxplot for column: score2