get_column_count

get_column_count(data)

Get the number of columns in a table.

The get_column_count() function returns the number of columns in a table. The function works with any table that is supported by the pointblank library, including Pandas, Polars, and Ibis backend tables (e.g., DuckDB, MySQL, PostgreSQL, SQLite, Parquet, etc.).

Parameters

data : FrameT | Any

The table for which to get the column count, which could be a DataFrame object or an Ibis table object. Read the Supported Input Table Types section for details on the supported table types.

Returns

: int

The number of columns in the table.

Supported Input Table Types

The data= parameter can be given any of the following table types:

  • Polars DataFrame ("polars")
  • Pandas DataFrame ("pandas")
  • DuckDB table ("duckdb")*
  • MySQL table ("mysql")*
  • PostgreSQL table ("postgresql")*
  • SQLite table ("sqlite")*
  • Parquet table ("parquet")*

The table types marked with an asterisk need to be prepared as Ibis tables (with type of ibis.expr.types.relations.Table). Furthermore, using get_column_count() with these types of tables requires the Ibis library (v9.5.0 or above) to be installed. If the input table is a Polars or Pandas DataFrame, the availability of Ibis is not needed.

Examples

To get the number of columns in a table, we can use the get_column_count() function. Here’s an example using the small_table dataset (itself loaded using the load_dataset() function):

import pointblank as pb

small_table_polars = pb.load_dataset("small_table")

pb.get_column_count(small_table_polars)
8

This table is a Polars DataFrame, but the get_column_count() function works with any table supported by pointblank, including Pandas DataFrames and Ibis backend tables. Here’s an example using a DuckDB table handled by Ibis:

small_table_duckdb = pb.load_dataset("small_table", tbl_type="duckdb")

pb.get_column_count(small_table_duckdb)
8

The function always returns the number of columns in the table as an integer value, which is 8 for the small_table dataset.