pyspark.sql.functions.
count
Aggregate function: returns the number of items in a group.
New in version 1.3.0.
Changed in version 3.4.0: Supports Spark Connect.
Column
target column to compute on.
column for computed results.
Examples
Count by all columns (start), and by a column that does not count None.
None
>>> df = spark.createDataFrame([(None,), ("a",), ("b",), ("c",)], schema=["alphabets"]) >>> df.select(count(expr("*")), count(df.alphabets)).show() +--------+----------------+ |count(1)|count(alphabets)| +--------+----------------+ | 4| 3| +--------+----------------+